Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2005

Tip: Looking for answers? Try searching our database.

Color table cells

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Metallo - 05 Aug 2005 14:15 GMT
Hi,

Can anybody tell me the code on how to shade the table cells so that when
entering Y it colors in Green and when entering N it colors in Red?

Thank you
Alex
Greg - 05 Aug 2005 18:00 GMT
Alex,

This can be automated unless you are using a proteccted form.  If it a
simple table and you can wait until your data is entered then process
the entire table or column of cells, you can do it with a macro.  Here
is and example that will process the cells in column three of the first
table in a document:
Sub Test()
Dim oCol As Column
Dim oCell As Cell
Dim myRange As Range

Set oCol = ActiveDocument.Tables(1).Columns(3)
For Each oCell In oCol.Cells
 Set myRange = oCell.Range
 myRange.End = myRange.End - 1
 If myRange.Text = "y" Then
   oCell.Shading.BackgroundPatternColor = wdColorGreen
 ElseIf myRange.Text = "n" Then
   oCell.Shading.BackgroundPatternColor = wdColorRed
 Else
   'Do nothing
 End If
Next
End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.