ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Visual Basic (https://www.excelbanter.com/excel-programming/295861-visual-basic.html)

[email protected]

Visual Basic
 
I wrote a simple macro which changes the value of cell "A1" on the first worksheet in a workbook which contains many worksheets. Obviously, I can execute the macro from any worksheet in the workbook. However, how do I modify the macro to RETURN to the specific worksheet I was in when I executed the macro, without specifying a specific sheet? In other words, I just want the macro to bring me back to whatever sheet I was in, when I executed the macro in the first place.

mn[_2_]

Visual Basic
 
when the code starts us
"set currentWorkSheet=Activeworkbook.ActiveSheet", so you can keep the reference
After you've done whatever you wanted d
currentWorkSheet.activat


Bob Phillips[_6_]

Visual Basic
 
Don't leave it.

That is

Worksheets(1).Range("A1").Value = "xx"

rather than

Worksheets(1).ACtivate
Range("A1").Value = "xx"

or (even worse)

Worksheets(1).ACtivate
Range("A1").Select
Selection.Value = "xx"


--

HTH

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

" wrote in message
...
I wrote a simple macro which changes the value of cell "A1" on the first

worksheet in a workbook which contains many worksheets. Obviously, I can
execute the macro from any worksheet in the workbook. However, how do I
modify the macro to RETURN to the specific worksheet I was in when I
executed the macro, without specifying a specific sheet? In other words, I
just want the macro to bring me back to whatever sheet I was in, when I
executed the macro in the first place.




All times are GMT +1. The time now is 09:16 AM.

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