Selection Range of sheets

Dannyh1

Well-known Member
Joined
Nov 18, 2009
Messages
1,144
H

i I think this is a simple one

I am trying to do an activity on range of sheets using "For Each" (sheet in range of sheets)

As a Range would be defined as A1:A100 for eg., how would do you write this for a Range of sheets

1st sheet 'KENNETH WRIGHT', last sheet 'SANDRA WOODS'

Many thanks
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Try something like

Rich (BB code):
Dim c As Range, ws As Worksheet
'MasterSheet is the sheet holding the range of sheet names.
For Each c in Sheets("MasterSheet").Range("A1:A100")
    Set ws = Sheets(c.Value)
    'Do stuff using ws as the sheet reference.
    ws.Range("A1").Value = "This is Sheet " & ws.Name
Next c
 

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
Hi, Perhaps:-
Code:
[COLOR=navy]Sub[/COLOR] MG03Aug59
[COLOR=navy]Dim[/COLOR] Shts, Sht
[COLOR=navy]Dim[/COLOR] Rng [COLOR=navy]As[/COLOR] Range, Dn [COLOR=navy]As[/COLOR] Range
Shts = Array("KENNETH WRIGHT", "MICKG", "SANDRA WOOD")
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Sht [COLOR=navy]In[/COLOR] Shts
    [COLOR=navy]With[/COLOR] Sheets(Sht)
        [COLOR=navy]Set[/COLOR] Rng = .Range("A1:A100")
            [COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Dn [COLOR=navy]In[/COLOR] Rng
                Dn = Sht
                '[COLOR=green][B]Do something Here !![/B][/COLOR]
            [COLOR=navy]Next[/COLOR] Dn
    [COLOR=navy]End[/COLOR] With
 [COLOR=navy]Next[/COLOR] Sht
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
 

Watch MrExcel Video

Forum statistics

Threads
1,133,636
Messages
5,659,994
Members
418,541
Latest member
bugsoup

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
Top