Color table cells

M

Metallo

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
 
G

Greg

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
 

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