Cat On A Spreadsheet
In the previous post, we parsed logs using simple string functions like Mid and Instr. However, regular expressions (regex) provide much more flexibility for pattern matching, validation, and extraction.
Suppose your log lines look like this:
The following script will extract:
Timestamp
Log level
Message
๐ Pattern Explanation
Pattern Matches
\[(.*?)\] Anything inside square brackets (timestamp)
\s+ One or more spaces
(\w+) Log level (INFO, ERROR, etc.)
: Literal colon
\s+ One or more spaces
(.*) The entire message
Extract email addresses
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
Extract numbers
\d+
Extract words inside quotes
"([^"]*)"
Regex-based parsing transforms your log file handling from brittle string splits to robust, pattern-driven data extraction. Combine this with dictionaries or advanced UDF libraries to build efficient parsers for any data source.
You might want to add headers for clarity:
You can call this sub before running ParseLogFile.
โ ๏ธ Bonus: Handling Irregular Lines
Some logs may have missing or malformed entries. Use error handling:
While tools like Python are more common for text processing, VBA offers:
Native integration with Excel
Immediate visualization and manipulation of parsed data
A great option for non-developers working in Excel-driven environments
VBA is more than just forms and macrosโitโs a lightweight data processing engine built right into Excel. With a bit of string manipulation and file handling, you can turn chaotic log files into structured, actionable data in minutes.
Want to go further? Try:
Parsing multi-line log entries
Highlighting rows with ERROR or WARN
Exporting results as a CSV or Excel table
Cat On A Spreadsheet