How to Compare Two Text Columns and Highlight Differences Using VBA
Question details
The user needs to compare text in two spreadsheet columns word by word, highlighting differences, marking missing words, and distinguishing punctuation changes using specific font colors.

- Product
- Spreadsheet
- Device & OS
- not provided
- Scenario
- Reviewing or auditing text data across two columns where visual identification of exact word or punctuation changes is required at the character level.
- Observed behavior
- Standard functions only compare whole cell values. The user requires an automated VBA solution to format text character-by-character based on a comparative logic.
Always create a backup copy of your workbook before running complex text manipulation macros, as actions performed by VBA cannot be undone using the standard Undo feature.
Create and Run a VBA Macro for Word-by-Word Text Comparison
Use a custom VBA macro to tokenize text, compare words and punctuation, and apply character-level rich text formatting to highlight discrepancies.
This approach involves writing a VBA script that reads the text from Column A and Column B. The macro splits the text into individual words and punctuation tokens, compares the sequences, and rebuilds the text in Column B. It applies specific formatting such as red bold for spelling differences, inserts '(missing)' for absent words, and uses blue formatting for punctuation variances.
Press `ALT + F11` to open the Visual Basic for Applications (VBA) editor in your spreadsheet.
Click on `Insert` in the top menu, then select `Module`. This creates a blank code window for your macro.
Paste your custom text comparison script into the module. Ensure your script utilizes string splitting logic (like the `Split` function) and uses `Cell.Characters(Start, Length).Font.Color` to apply specific colors to the differences.
Close the VBA Editor. Select the range of cells you want to process, press `ALT + F8`, select your newly created macro, and click `Run`.
Use WPS Spreadsheet to Run VBA Macros and Compare Data
WPS Office Spreadsheet provides excellent support for VBA macros, allowing you to easily automate complex text comparisons, highlight differences, and format cells character by character without needing heavy software.
- 1. Open WPS Spreadsheet: Launch WPS Office and open the workbook containing the text columns you wish to compare.
- 2. Access Developer Tools: Navigate to the `Tools` tab and click on `Developer` to reveal the macro and VBA options.
- 3. Edit and Execute VBA: Click on `Visual Basic Editor` to paste your comparison macro, then run it to automatically analyze and highlight text differences.

Frequently Asked Questions
Can I undo the formatting changes made by this VBA macro?
No, actions executed via VBA clear the standard Undo history. You must manually revert the formatting or, preferably, run the macro on a backup copy of your data.
Does WPS Office support VBA for text manipulation?
Yes, WPS Spreadsheet fully supports VBA macros, including advanced string manipulation functions like `Split`, `InStr`, and the `Characters.Font` properties necessary for this task.
How can I compare columns without using VBA?
If you do not need word-by-word highlighting inside the cell, you can use the `EXACT` function (e.g., `=EXACT(A1, B1)`) or Conditional Formatting using the formula `=$A1<>$B1` to highlight entire cells that do not match.
Why is the character formatting not applying properly to long text?
Spreadsheet cells have a limit on the number of character-level font formats they can store, and processing extremely long text strings may cause the VBA macro to time out or apply formatting inaccurately. Break down large text blocks into smaller cells if possible.




