Worksheet Select Macro

Discussion regarding the spreadsheet functionality of Bet Angel.
Post Reply
thewald
Posts: 28
Joined: Sat Oct 30, 2010 11:46 am

Hi

Hoping somebody can help please.

Have been using the record macro feature and have managed to create the macros I need and attach them to a button, but I can only get them to work in the worksheet where the button is

What would I need to add to my code to specify 'Sheet 3" as the only sheet for the particular macro to run on?

Thanks in advance

Good Luck this week to those trading/betting at Cheltenham
nigelk
Posts: 469
Joined: Wed Apr 15, 2009 11:00 pm

The macro will run on whatever sheet is active at the time.

You can write something along the lines of:

Sheets("Sheet3").Range("A2").formula..........
Sheets("Sheet3").Range("B2")=.........

But it's easier to use "With", then you don't need all that typing.

With Sheets("Sheet3")

.Range("A2").formula..........
.Range("B2")=.........

.other code............

End With

Just remember to preface each instruction with a dot.

Cheers.
thewald
Posts: 28
Joined: Sat Oct 30, 2010 11:46 am

Thanks Nigel

Will give it a try tonight
nigelk
Posts: 469
Joined: Wed Apr 15, 2009 11:00 pm

Forgot to say that the easiest way would be just to put

Sheets("Sheet3").Select

at the beginning of the macro. But that creates it's own problems as you could find it crashing if you switch to another sheet while it's running. All depends on what you need to do.
Post Reply

Return to “Bet Angel - Spreadsheet / Excel chat”