Check Cell Text Length and Report Errors with an Excel VBA Macro
Question details
Create a macro that finds product-template cells with values longer than 32 characters and reports their locations.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A product template needs its cells in columns X through Z, rows 21 through 7100, checked against a 32-character limit.
- Observed behavior
- Cells exceeding the limit should be identified by row and column.
Confirm the name of the worksheet containing the product template and verify that X21:Z7100 is the range to check. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) if you want to retain the macro.
Run a VBA macro to report cells over 32 characters
Use this macro to check each cell in X21:Z7100 and display its column and row when its value exceeds the limit.
Open the workbook in desktop Excel, then press Alt+F11 or select Developer > Visual Basic.
In the VBA editor, select the workbook project and choose Insert > Module. Paste the following code, replacing Product Template with the exact worksheet name: Sub CheckLength() Dim ws As Worksheet Dim i As Long, j As Long Set ws = ThisWorkbook.Worksheets("Product Template") For i = 21 To 7100 For j = 24 To 26 If Not IsError(ws.Cells(i, j).Value) Then If Len(ws.Cells(i, j).Value) > 32 Then MsgBox "Error in column: " & j & " row: " & i End If End If Next j Next i MsgBox "Length check complete." End Sub
Return to Excel, select Developer > Macros, choose CheckLength, and click Run. Dismiss each message to continue checking the remaining cells.

Find overlength cells with WPS Spreadsheets
Use helper formulas in WPS Spreadsheets to identify cells over 32 characters by address, without running VBA.
- 1. Open the template: Open the workbook in WPS Spreadsheets and select the product-template worksheet.
- 2. Enter a helper formula: If columns AA through AC are empty and available, enter =IF(LEN(X21)>32,ADDRESS(ROW(X21),COLUMN(X21),4),"") in cell AA21.
- 3. Fill the check range: Copy AA21 across to AC21, then select AA21:AC21 and fill the formulas down through row 7100. The three helper columns check X, Y, and Z respectively.
- 4. Review the results: Look for displayed cell addresses in AA21:AC7100, or use Data > Filter to show nonblank results in one helper column at a time. Clear that filter before checking another helper column.

Frequently Asked Questions
How do I change the 32-character limit?
In the VBA editor, change > 32 in the If Len(...) line to the desired limit. The macro reports values longer than that number, not values equal to it.
How can I check different rows or columns?
In the macro, change For i = 21 To 7100 to the desired row numbers and For j = 24 To 26 to the desired column numbers. Column 24 is X, 25 is Y, and 26 is Z.
Why does the macro need a worksheet name?
The line Set ws = ThisWorkbook.Worksheets("Product Template") ensures the macro checks the intended sheet in the workbook containing the code. Replace Product Template with the sheet's exact name.
Can I check cell lengths without enabling macros?
Yes. In WPS Spreadsheets, use a helper formula such as =IF(LEN(X21)>32,ADDRESS(ROW(X21),COLUMN(X21),4),"") and fill it across and down to display the addresses of overlength cells.




