VBA Check for Total and Bold the Range based on criteria

Hi,
I am trying to bold the a range based on criteria, Can you please help what is wrong with this VBA code.

Sub test1()
Worksheets("Forms").Range("O5:T10").Font.Bold = False
Dim i As Integer
Dim j As Integer
For i = 5 To 10
If Worksheets("Forms").Cells(i, 15) = "Grand Total" Then
j = i
End If
Next i
Worksheets("Forms").Range("Oj:Tj").Font.Bold = True
End Sub

It is not making that range bold.

Thank you

Expert Asked on March 3, 2017 in VBA: Macros.
Add Comment
1 Answer(s)

Here is the updated procedure, we have corrected the statement 17 in your code:

Sub test1()
Worksheets("Forms").Range("O5:T10").Font.Bold = False
Dim i As Integer
Dim j As Integer
For i = 5 To 10
If Worksheets("Forms").Cells(i, 15) = "Grand Total" Then
j = i
End If
Next i
Worksheets("Forms").Range("O" & j & ":T" & j).Font.Bold = True
'The above statement is corrected
End Sub

Here is the optimized code:

Sub test1()
Worksheets("Forms").Range("O5:T10").Font.Bold = False
Dim i As Integer
For i = 5 To 10
If Worksheets("Forms").Cells(i, 15) = "Grand Total" Then
Worksheets("Forms").Range("O" & i & ":T" & i).Font.Bold = True
Exit For
End If
Next i
End Sub

Thanks -PNRao!

Keymaster Answered on March 3, 2017.
Add Comment
  • Found this useful?

    Please share using the share button above.

    If you found the answer is best answer for your question, Please mark as 'best answer' by clicking on the right tick mark icon at the left side of the answer.

    Found the answer useful and wants to credit the user, then vote the answer (vote up).

  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.