Macro

J

JohnR

Anyone have a simple method (relatively) of highlighting (any color) a row
in a table that contains a known string of numbers ??
What I have is a table 300(+) rows 10 columns that I paste from a telephone
call list. I'd like to be able to highlight (or otherwise mark) all rows
that contain a specific number or time or any particular column. I would
input the search string.
Sounds like I need a macro ?


Thanks
John
 
L

Lynn

Try this - it loops through every row in the table, for every row it
finds, it checks every cell in the row. If the text in the cell (minus
the cell marker) matches the text you typed in the box, it selects the
whole row and highlights it Pink. You can change the colour if you
want.

Sub highlightrows()

Dim objRow As Row
Dim objCell As Cell
Dim objTable As Table
Dim rngCell As Range
Dim sText, sTextCell As String
Dim i, x As Integer

Set objTable = ActiveDocument.Tables(1)

sText = InputBox("Type Number or Time")
If Len(sText) = 0 Then
Exit Sub
End If
i = 1
For Each objRow In objTable.Rows
x = objTable.Rows(i).Cells.Count
For Each objCell In objTable.Rows(i).Cells
Set rngCell = objTable.Rows(i).Cells(x).Range
rngCell.MoveEnd Unit:=wdCharacter, Count:=-1
sTextCell = rngCell.Text
If sTextCell = sText Then
objRow.Select
Selection.Shading.BackgroundPatternColor = wdColorPink
End If
x = x - 1
Next
i = i + 1
Next

End Sub

Regards Lynn
 
J

JohnR

Looks good for what I need. I had a friend correct my typing errors, and
its working.
Thanks
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top