How to Remove Tab Characters from Excel Cells Using VBA
Question details
The user needs a method to remove actual tab characters from text within Excel cells using VBA, while ensuring ordinary spaces remain intact.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Cleaning numeric or alphanumeric data pasted from external sources that contains hidden tab characters, which are causing data validation or processing errors.
- Observed behavior
- Hidden tab characters in the data interfere with cell validation and data processing, requiring a programmatic cleanup.
Before running any VBA macro, ensure you have saved a backup copy of your workbook, as actions performed by macros cannot be undone using the standard Undo feature.
Use VBA Replace Method with the vbTab Constant
Execute a straightforward VBA script utilizing the vbTab constant to find and replace all tab characters within a specific column.
This is the most efficient method for stripping tab characters. By specifically targeting the built-in VBA constant 'vbTab', it ensures that normal spaces (ASCII 32) are entirely unaffected.
Press Alt + F11 on your keyboard to launch the VBA Editor in Excel.
In the VBA Editor, click on 'Insert' in the top menu bar and select 'Module' from the dropdown list.
Paste the following code into the module window: Sub RemoveTabs() Columns("K").Replace What:=vbTab, Replacement:="", LookAt:=xlPart End Sub. Change the letter 'K' to match the column containing your data.
Click inside the code and press F5, or click the 'Run' button in the toolbar to execute the macro and clean the selected column.
Use the SUBSTITUTE Function (Formula Alternative)
If you prefer not to use VBA macros, you can use built-in Excel formulas to strip tab characters by referencing their ASCII character code.
Easily Clean Tab Characters with WPS Spreadsheet
WPS Spreadsheet fully supports VBA macros, allowing you to run your data-cleaning scripts seamlessly. You can execute the exact same VBA code in WPS to remove tab characters and format your data.
- 1. Open your workbook in WPS Spreadsheet: Launch WPS Office and open the file containing the data with tab characters.
- 2. Access the Developer Tools: Navigate to the 'Developer' tab on the ribbon and click on 'Visual Basic' or 'WPS Macro'.
- 3. Insert and Run the Code: Insert a module, paste the Columns("K").Replace What:=vbTab, Replacement:="" code, and run it to instantly clean your data.

Frequently Asked Questions
Why do my Excel cells have tab characters in them?
Tab characters often appear when data is copied and pasted from external sources like websites, PDF documents, or text editors where tabs are used for formatting, indentation, or separation.
What is the ASCII character code for a tab in Excel?
The ASCII code for a horizontal tab character is 9. In Excel formulas, it is represented as CHAR(9), while in VBA, it is referenced using the built-in constant vbTab.
Will this VBA code delete normal spaces between words?
No. The VBA constant vbTab specifically targets tab characters. Regular spaces (ASCII 32) and non-breaking spaces are completely ignored by this replacement code.
Can I apply this VBA script to the entire worksheet instead of just one column?
Yes, you can modify the VBA code to search the entire sheet. Simply replace Columns("K") with Cells to make it: Cells.Replace What:=vbTab, Replacement:="", LookAt:=xlPart.




