Home |
Search |
Today's Posts |
#1
![]() |
|||
|
|||
![]()
Hi, I'm looking for a way to automatically add shading to a row of
cells. What I have is a two-column table, and I'd like to shade the rows which contain a particular word in the first cell. I can't find a way to do this using table styles, so I think a macro is the way forward. My VB is pretty much nonexistent but I'm willing to learn...can anyone point me in the right direction to get me started? Using Word 2003, Win XP. Thanks |
#2
![]() |
|||
|
|||
![]()
AOH,
I am a VBA beginner myself and so the code I am providing can probably be improved. Still it seems to work. Sub ScratchMacro() 'Looks for the text string "????" in the first column and shades 'the corresponding row. Replace "????" in the InStr expression below with the 'word or text string you want to search for Dim oCell As Cell Dim oRow As Row Dim oCol As Column Dim oTable As Table Dim i As Long If Selection.Information(wdWithInTable) = True Then Set oTable = Selection.Tables(1) Set oCol = Selection.Columns(1) i = 0 Else MsgBox "Selection is not in a table" Exit Sub End If For Each oCell In oCol.Cells i = i + 1 If InStr(oCell.Range.Text, "????") = 1 Then Set oRow = oTable.Rows(i) oRow.Shading.BackgroundPatternColorIndex = wdGray25 Set oRow = Nothing End If Next End Sub -- Greg Maxey/Word MVP A Peer in Peer to Peer Support AOH wrote: Hi, I'm looking for a way to automatically add shading to a row of cells. What I have is a two-column table, and I'd like to shade the rows which contain a particular word in the first cell. I can't find a way to do this using table styles, so I think a macro is the way forward. My VB is pretty much nonexistent but I'm willing to learn...can anyone point me in the right direction to get me started? Using Word 2003, Win XP. Thanks |
#3
![]() |
|||
|
|||
![]()
Greg, that's fantastic - works exactly as I wanted. Thanks a lot!
|
Reply |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Selecting Table Cells | Tables | |||
Why is shading in the cells of tables in Word 11 not visible anymo | Tables | |||
shading does not reach left border | Tables | |||
How do I link cells in a table? | Tables | |||
Shading does not fill entire cell | Tables |