Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default For Each, Next

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default For Each, Next

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

--
Regards
Frank Kabel
Frankfurt, Germany


wrote:
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default For Each, Next

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)

wrote in message
...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"