Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to change Scenario........

Status
Not open for further replies.

Jamie2002

Technical User
Sep 17, 2001
62
0
0
GB
I have made Excel record a macro of me changing a scenario.....then looking at the code it produced the following;

ActiveSheet.Scenarios("Scenario1").Show

When I try and run this pre-recorded Macro though I get the following error;

Run-Time Error '1004';
Show Method of Scenario Class failed

Can Scenarios be changed using code so that they can then be allocated to a button ? If so am I best using Form buttons or Control buttons ?

Thanks

Jamie. Thanks

Jamie
 
A 1004 error usually means that something is missing. In this case, I would guess that the "Activesheet" doesn't have a scenario, or that the name is different to the one you are using. If you want to run it from a button, I would suggest a Forms button as you will then just be able to assign a macro. Also, you shouldn't need to explicitly reference the sheet (unlike with a controls button)

Word to the wise - be very careful when using Activesheet. If you are in the VB Editor, Activesheet, will refer to whichever sheet is currently selected in excel (not necessarily the one you want). It can also, in certain circumstances, refer to the module itself.

HTH
~Geoff~
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top