Highlighting special characters in a string
On Fri, 7 Nov 2008 00:43:00 -0800, Cynthia
wrote:
Hi Ron,
Thanks for your help but I am still not getting all the rows with special
characters in column A to D hightlighted automatically.
I still have to go in and change the column names individually.
Regards
Cynthia
That has to do with how you step through the range. As written, if you specify
a multi-column range, all the cells in any particular row would have to fail
the test.
To check for just a single cell failing the test, do something like:
==============================
Option Explicit
Sub NonDigits()
Dim rg As Range
Dim rw As Long, col As Long
Set rg = Range("A1:D10") 'Range to be checked
For rw = 1 To rg.Rows.Count
rg(rw, 1).EntireRow.Interior.Color = xlNone
For col = 1 To rg.Columns.Count
With rg(rw, col)
If Not .Text Like Application. _
WorksheetFunction.Rept("#", Len(.Text)) Then
.EntireRow.Interior.Color = vbRed
End If
End With
Next col
Next rw
End Sub
===============================
--ron
|