VBA - Table -cell shading on exit of file

D

Dee

Hi

I have a template where there is a table with 4 columns and 10 rows. The
rist column records an "action" and a risk level (number) has to be recorded
in col 2 col 3 would be the mitigated risk to the action and col 4 the risk
factor after the risk is mitigated.
I need to update the colors of the cells depending on the numbers entered in
col 2 and 4 on exit of the file.
Any help on how to do this will be deeply appreciated.
Rgds Dee
 
G

Greg Maxey

Something like this perhaps:

Private Sub Document_Close()
Dim oCOl As Column
Dim oCell As Cell
Dim myRange As Range
Dim i As Long
For i = 2 To 4 Step 2
Set oCOl = ActiveDocument.Tables(1).Columns(i)
For Each oCell In oCOl.Cells
Set myRange = oCell.Range
myRange.End = myRange.End - 1
Select Case myRange.Text
Case Is < 4
oCell.Shading.BackgroundPatternColor = wdColorGreen
Case 4 To 7
oCell.Shading.BackgroundPatternColor = wdColorYellow
Case Else
oCell.Shading.BackgroundPatternColor = wdColorRed
End Select
Next oCell
Next i
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