I have the following VBA code and it seems to work partially? Sometimes it works, and sometimes it doesnt. I am getting a type mismatch error on the "If Len(c.Value) > 30 And c.Row <> 1" Then line. Any help would be great, thanks.
Sub GSSLength()
Dim c As Range
Dim ws As Worksheet
Dim j As Long
j = 0
For Each ws In ActiveWorkbook.Worksheets
If ws.Name Like "BOM" Then
For Each c In ws.Range("A2:R10000")
If Len(c.Value) > 30 And c.Row <> 1 Then
ws.Cells(c.Row, c.Column).Interior.ColorIndex = 3
j = j + 1
End If
Next c
End If
Next ws
If j > 0 Then
MsgBox j & " errors found where the length of cell is longer than 30 characthers, please correct in columns that are red."
End If
End Sub
cwhen it fails?c.Row <> 1will always beTrueby the way, if you're looping overws.Range("A2:R10000").cis already referencing the row and column as well so you could consolidatews.Cells(c.Row, c.Column).Interior.ColorIndex = 3toc.Interior.ColorIndex = 3