ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to end macro on inital active worksheet containing macro button that was clicked (https://www.excelbanter.com/excel-programming/298319-how-end-macro-inital-active-worksheet-containing-macro-button-clicked.html)

Silverhawk1

How to end macro on inital active worksheet containing macro button that was clicked
 
I developed a formating macro that can be run by clicking a button on anyone of 20 worksheets. Currently the macro always ends on the 20th worksheet. How can I get the macro to return me to the worksheet I was on when the macro was activated?

Bob Phillips[_6_]

How to end macro on inital active worksheet containing macro button that was clicked
 

Set shFirst = Activesheet
'do your bit
shFirts.Activate

--

HTH

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

"Silverhawk1" wrote in message
...
I developed a formating macro that can be run by clicking a button on

anyone of 20 worksheets. Currently the macro always ends on the 20th
worksheet. How can I get the macro to return me to the worksheet I was on
when the macro was activated?



Ron de Bruin

How to end macro on inital active worksheet containing macro button that was clicked
 
Hi Silverhawk1

For most of the things you don't have to select the sheets in the loop.
Then your sheet stay active.

But if you must select then you can use this

Sub test()
Dim Asheet As Worksheet
Set Asheet = ActiveSheet

' your code


Asheet.Select
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Silverhawk1" wrote in message ...
I developed a formating macro that can be run by clicking a button on anyone of 20 worksheets. Currently the macro always ends on

the 20th worksheet. How can I get the macro to return me to the worksheet I was on when the macro was activated?




All times are GMT +1. The time now is 05:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com