Help!! Need to run macro on multiple worksheets...

G_Olson

New Member
Joined
Sep 10, 2010
Messages
7
I have multiple worksheets that I need to run the same macro on. I've tried several code examples I found online to do this, but none of them will work using my code (which works fine on individual worksheets). They work fine when running "as is", but won't cycle through the worksheets when I insert my code. The macro just keeps running on the first worksheet multiple times instead of stepping through them!?

Here's some simple code I tried that worked fine "as is"...


Public Sub BoldAllSheets()
Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
ws.Range("1:1").Font.Bold = True
Next ws

End Sub


When I replace ws.Range("1:1").Font.Bold = True with my code it will NOT cycle through the worksheets. Again, it just runs multiple times on the first worksheet. I can email files/code if needed. Any help would be much appreciated.
 
Try

Code:
Sub VoG()
Dim ws As Worksheet
Dim c As Range
Dim rng As Range
For Each ws In ThisWorkbook.Worksheets
    With ws
        For Each c In Intersect(.UsedRange, .Columns("f"))
            If c.Value = "," Then
                If rng Is Nothing Then Set rng = c.EntireRow
            Else
                Set rng = Union(rng, c.EntireRow)
            End If
        Next c
        'rng.Select  this won't work
        rng.Interior.ColorIndex = 3
    End With
Next ws
End Sub
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
VoG,

Thanks for your help on this. A mistake on my part...the stuff I said wasn't working in my last post does work...I just set my breakpoint at the wrong place. SO...back to where I started. My code works on a single worksheet...just not when i try to step through multiple worksheets. :confused:
 
Upvote 0

Forum statistics

Threads
1,223,982
Messages
6,175,776
Members
452,668
Latest member
mrider123

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