VBA highlight subtotal and grand total on multiple sheets

galmond1010

New Member
Joined
Apr 15, 2019
Messages
21
I would like to highlight column C with the text "Total" and "Grand Total" on multiple sheets using VBA. Can anyone assist? I have the VBA for a single sheet but can't seem to figure out how to go to the next sheet without debugging. Thank you in advance.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Welcome to the Board!

Post the code you have, and we can help you expand it.
Also, do you want this to apply to ALL the sheets in the workbook, or just certain ones?
If just certain ones, how can we identify which ones?
 
Upvote 0
Welcome to the Board!

Post the code you have, and we can help you expand it.
Also, do you want this to apply to ALL the sheets in the workbook, or just certain ones?
If just certain ones, how can we identify which ones?

Here is the code I current am using:
Dim rCell As Range
For Each rCell In Sheets("BURNS & ASSOC.").Range("C6:C10000")

If Right (rCell.Value,5) = "Total" Then
Rows(rCell.Row).Interior.ColorIndex = 36
End If
If Right(Rng.Value,11) = "Grand Total" Then
Rng.EntireRow.Interior.ColorIndex = 8
End If
Next

I have 31 individual sheets I would like to highlight subtotals in the same workbook.
 
Upvote 0
Try this:
Code:
Sub MyMacro()

    Dim ws As Worksheet
    Dim rCell As Range
    
    Application.ScreenUpdating = False
    
    For Each ws In Worksheets
        ws.Activate
        For Each rCell In Sheets("BURNS & ASSOC.").Range("C6:C10000")
            If Right(rCell.Value, 5) = "Total" Then
                Rows(rCell.Row).Interior.ColorIndex = 36
            End If
            If Right(Rng.Value, 11) = "Grand Total" Then
                Rng.EntireRow.Interior.ColorIndex = 8
            End If
        Next
    Next ws

    Application.ScreenUpdating = True

End Sub
 
Upvote 0
In this line you have the Rng object, but it does not exists:

Code:
[B][COLOR=#ff0000]Rng[/COLOR][/B][COLOR=#333333].EntireRow.Interior.ColorIndex = 8[/COLOR]

Try this:

Code:
Sub highlight_total()
    Dim sh As Worksheet, rCell As Range
    For Each sh In Sheets
        For Each rCell In sh.Range("C6", sh.Range("C" & Rows.Count).End(xlUp))
            If Right(rCell.Value, 5) = "Total" Then rCell.EntireRow.Interior.ColorIndex = 36
            If Right(rCell.Value, 11) = "Grand Total" Then rCell.EntireRow.Interior.ColorIndex = 8
        Next
    Next
End Sub
 
Upvote 0
By the way, you did not change the sheet either

Code:
[COLOR=#333333]For Each rCell In [/COLOR][COLOR=#ff0000]Sheets("BURNS & ASSOC.")[/COLOR][COLOR=#333333].Range("C6:C10000")[/COLOR]
;)
 
Upvote 0
By the way, you did not change the sheet either
Yeah, I meant to remove that part, since I am selecting the worksheet prior, i.e.
Code:
        ws.Activate
        For Each rCell In Range("C6:C10000")
Its been a long day, maybe I should quit now!
 
Last edited:
Upvote 0
Works like a charm. Thank you very much. Sorry about the original code, it was from an earlier attempt to highlight. I appreciate the help.
 
Upvote 0

Forum statistics

Threads
1,224,815
Messages
6,181,136
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top