View Single Post
 
Old 03-24-2022, 06:09 AM
diwakaramit diwakaramit is offline Windows 10 Office 2016
Novice
 
Join Date: Mar 2022
Posts: 5
diwakaramit is on a distinguished road
Default Conditional formatting of a word table

Hello-I have some experience with VBA in excel however i am new to VBA in word. I am trying to perform conditional formatting on the whole row within a Table in word report that i am creating.
I have multiple tables within this word document however i need to perform conditional formatting on Table (4). Table(4) has 5 rows and 4 columns. I need to loop through starting from Row 2 and check if the cell value in column 3 is 5 and value in column 4 is A. If this condition is true for that particular row then this whole row should be colored Red.
I prepared the code below but keep getting "Compile Error: Method or data member not found" on Line 8

Line 1 Sub Demo()
Line 2 Dim Rng As Range
Line 3 Dim rw As Integer
Line 4 Set Rng = ActiveDocument.Content
Line 5 With ActiveDocument.Tables(4)
Line 6 For rw = 2 To 5
Line 7 If .Cell(rw, 4).Range.Text = "5" And .Cell(rw, 5).Range.Text = "A" Then
Line 8 .Range.Cell(rw).Shading.BackgroundPatternColorInde x = wdDarkRed
Line 9 End If
Line 10 Next
Line 11 End With
Line 12 End Sub


Any help with this VBA code will be really helpful.
Any help with this VBA code will be really helpful.
Attached Files
File Type: docm RBI-REPORT-3.docm (35.4 KB, 8 views)
Reply With Quote