Reply
 
Thread Tools Display Modes
  #1   Report Post  
AOH
 
Posts: n/a
Default Shading cells based on content

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   Report Post  
Greg Maxey
 
Posts: n/a
Default

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   Report Post  
AOH
 
Posts: n/a
Default

Greg, that's fantastic - works exactly as I wanted. Thanks a lot!

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting Table Cells John Tables 1 December 15th 04 05:10 AM
Why is shading in the cells of tables in Word 11 not visible anymo Russell-joe Tables 1 December 8th 04 11:39 PM
shading does not reach left border Thea Tables 0 November 4th 04 02:19 PM
How do I link cells in a table? Tonia Tables 1 November 3rd 04 09:55 PM
Shading does not fill entire cell Fred Holmes Tables 1 October 28th 04 10:18 PM


All times are GMT +1. The time now is 04:15 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"