View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Jan Karel Pieterse Jan Karel Pieterse is offline
external usenet poster
 
Posts: 535
Default Executing Macro Help

Hi,

For example, I'm in Profits worksheet and choose best scenario from
the combo box, and it changes B92 in Rev tab. Also, is there a way to
keep focus on the worksheet and have it still execute the macro?


I assume your macro was recorded and uses things like :

Range("A1").DoSomething

If you want to do this on just one worksheet, surround your entire code
(inside a sub) with:

With Worksheets("YourSheet")
'Your code
End With

Now for each "Range" make sure you prepend it with a dot:

.Range(.......

This way your code now talks to ranges on "YourSheet".

To make sure that worksheet is visible, add:

.Activate

anywhere within the with...end with construction.

Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com
Member of:
Professional Office Developer Association
www.proofficedev.com