View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Highlight cells containing words of a given type

It worked, but stopped after a few rows

Is that after a few rows of your own test data (it worked fine with 400 rows
of
the SamplData test as posted).

Remove the error handler by commenting the On error resume next

report the string in the cell that fails and which line the code has failed
on

Can anyone help,
preferably with the regexp approach as the code is less?


Possibly a bit less but I wouldn't have thought much less by the time you
include all your
objectives. Also unless you are quite familiar with Regexp it would probably
take you longer to work out how to make small changes.

But if you want to use regexp there should be enough in the examples your
other thread which you could adapt and incorporate into the function I
posted. Before doing that, try and work out what the function does as
written.

Regards,
Peter T



"Raj" wrote in message news:40bd4f10-fa87-4227-b431-
Thanks Pete for the solution. It worked, but stopped after a few rows.
I will find out why.
In the meantime, exploring the regexp approach, I succeeded in making
the following code fill (interior.colorindex) cells containing one or
more matches:

Sub HighlightCells()
Dim w As Worksheet, c As Range
Set regexp = CreateObject("VBScript.RegExp")
regexp.Global = True
regexp.IgnoreCase = False
regexp.Pattern = "\b[A-Z0-9]+\b"
Set rng = Worksheets("Sheet1").Range("C1:C785")
For Each c In rng
Set rsp = regexp.Execute(c.Text)
If rsp.Count 0 Then c.Interior.ColorIndex = 6 ' Yellow color
interior for cell
Next
End Sub

I am stuck here. I would like the matching words displayed in bold in
addition to the cell being filled with yellow color. Can anyone help,
preferably with the regexp approach as the code is less?

Thanks,
Raj