View Single Post
 
Old 09-11-2019, 06:45 AM
KateWord KateWord is offline Windows 7 64bit Office 2007
Novice
 
Join Date: Sep 2019
Posts: 1
KateWord is on a distinguished road
Default How to run colour conditional formatting in just column, not whole table

Hi,

I have created a table, where I want one column to be colour coded based on their grade. When I run the macro though, it runs on the whole table rather than selected column.

Is there a way to get it to just run on selected column, or is there some code I could put in that would target the column based on a word included in the title, and then format that column only? Sure its something simple, but I'm new to this!

Dim c As Word.Cell
If Selection.Information(wdWithInTable) Then
For Each c In Selection.Tables(1).Range.Cells
If IsNumeric(Left(c.Range.Text, Len(c.Range.Text) - 1)) Then
If Val(c.Range.Text) = 1 Then
c.Shading.BackgroundPatternColor = 10669990
ElseIf Val(c.Range.Text) = 2 Then
c.Shading.BackgroundPatternColor = 12443072
ElseIf Val(c.Range.Text) = 3 Then
c.Shading.BackgroundPatternColor = 10546144
ElseIf Val(c.Range.Text) = 4 Then
c.Shading.BackgroundPatternColor = 12512766
ElseIf Val(c.Range.Text) = 5 Then
c.Shading.BackgroundPatternColor = 12440539
ElseIf Val(c.Range.Text) = 6 Then
c.Shading.BackgroundPatternColor = 9813759
ElseIf Val(c.Range.Text) = 7 Then
c.Shading.BackgroundPatternColor = 12233699
ElseIf Val(c.Range.Text) = 8 Then
c.Shading.BackgroundPatternColor = 12830711
ElseIf Val(c.Range.Text) = 9 Then
c.Shading.BackgroundPatternColor = 12830711
ElseIf Val(c.Range.Text) < 9 Then
c.Shading.BackgroundPatternColor = wdColorWhite

Else
c.Shading.BackgroundPatternColor = wdColorWhite
End If
Else ' set non-numeric to White
c.Shading.BackgroundPatternColor = wdColorWhite
End If
Next
End If

End Sub
Reply With Quote