For Each, Next

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the following macro than contains another macro:

Sub MonthList()

Dim wks As Worksheet

For Each wks In Worksheets
OtherMacro
Next wks

End Sub

However, when i run it, OtherMacro (a list of months) only
get executed in the active worksheet. What am i doing
wrong?

regards
 
Hi
you probably hardcoded the activesheet in your 'othermacro'. You have
to pass the worksheet object to your other macro and use this as
reference for your macro
 
Not the correct approach IMO, Frank's suggestion is the way to go, but you
could do this

Sub MonthList()

Dim wks As Worksheet
Dim orig as Worksheet

Set orig = Activesheet
For Each wks In Worksheets
wks.Activate
OtherMacro
Next wks
orig.Activate

End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top