VBA Code for Making Entire Rows Bold based on a Cell value in the Query table

33.3k views Asked by At

I have a table in the range (G15:AL540) generated through SAP Query. I need to make all the rows Bold if the Cells in Column L Contains the word "Main Investigation". I did it using Conditional Formatting (=$L16="Main investigation") and it worked. But I need to write it in VBA, so that this formatting is applied automatically when the Query is refreshed.

Thanks!

1

There are 1 answers

1
99moorem On BEST ANSWER

This will only work for active sheet, change activesheet to sheets("sheetabc") to reference another sheet

Sub test()
With ActiveSheet
    For Each cell In .Range("G15:" & .Range("G15").End(xlDown).Address)
        If .Cells(cell.Row, 12).Value = "Main investigation" Then
            cell.EntireRow.Font.Bold = True
        End If
    Next
End With
End Sub