ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code for Returning to Last Active Worksheet Please (https://www.excelbanter.com/excel-programming/378775-re-code-returning-last-active-worksheet-please.html)

Don Guillett

Code for Returning to Last Active Worksheet Please
 
This should work from the sheet where you were before firing the macro.
However, WHY are you going to another sheet in the first place. It is rarely
necessarry to do so. Your instructions could be a msgbox or a userform or ?

Sub gobacktosheet()
Previous = ActiveSheet.Index
Application.Goto Sheets("sheet2").Range("a2")
MsgBox "Hi"
Sheets(Previous).Select
End Sub

--
Don Guillett
SalesAid Software

"Carl" wrote in message
...
Can anyone tell me the code to use in a macro to return the user to the
last
active worksheet? The user is being sent to a worksheet containing
instructions but needs to be able to return to the last worksheet visited.
"ActiveSheet.Previous.Select" did not work. Thanks in advance.




Don Guillett

Code for Returning to Last Active Worksheet Please
 
to goto Sheets("sheet2").Range("a2") you don't need to know where they came
from if your instruction sheet was sheet2. You could use

sheets("Instructions").select
activesheet.printout

--
Don Guillett
SalesAid Software

"Carl" wrote in message
...
Thanks, Don. Good question. I have one major worksheet containing hundreds
of
rows of instructions so the user can find/print them all from one place. I
could not use the command [Application.Goto since I don't know from
which sheet they have come. Thanks again.

"Don Guillett" wrote:

This should work from the sheet where you were before firing the macro.
However, WHY are you going to another sheet in the first place. It is
rarely
necessarry to do so. Your instructions could be a msgbox or a userform or
?

Sub gobacktosheet()
Previous = ActiveSheet.Index
Application.Goto Sheets("sheet2").Range("a2")
MsgBox "Hi"
Sheets(Previous).Select
End Sub

--
Don Guillett
SalesAid Software

"Carl" wrote in message
...
Can anyone tell me the code to use in a macro to return the user to the
last
active worksheet? The user is being sent to a worksheet containing
instructions but needs to be able to return to the last worksheet
visited.
"ActiveSheet.Previous.Select" did not work. Thanks in advance.







Don Guillett

Code for Returning to Last Active Worksheet Please
 
How about marking the instruction sheet?

Sub gotoinstructionsheet()' to goto Instruction sheet
Previous = ActiveSheet.Name
Application.Goto Sheets("Instructions").Range("a2")'any cell
ActiveCell = Previous
End Sub

Sub gobacktoprev()'attach to button on Instruction sheet
Previous = Range("a2")'same cell as above
Sheets(Previous).Select
End Sub

--
Don Guillett
SalesAid Software

"Carl" wrote in message
...
Thanks, Don. Good question. I have one major worksheet containing hundreds
of
rows of instructions so the user can find/print them all from one place. I
could not use the command [Application.Goto Sheets("sheet2").Range("a2")]
since I don't know from which sheet they have come. Thanks again.

"Don Guillett" wrote:

This should work from the sheet where you were before firing the macro.
However, WHY are you going to another sheet in the first place. It is
rarely
necessarry to do so. Your instructions could be a msgbox or a userform or
?

Sub gobacktosheet()
Previous = ActiveSheet.Index
Application.Goto Sheets("sheet2").Range("a2")
MsgBox "Hi"
Sheets(Previous).Select
End Sub

--
Don Guillett
SalesAid Software

"Carl" wrote in message
...
Can anyone tell me the code to use in a macro to return the user to the
last
active worksheet? The user is being sent to a worksheet containing
instructions but needs to be able to return to the last worksheet
visited.
"ActiveSheet.Previous.Select" did not work. Thanks in advance.








All times are GMT +1. The time now is 09:53 PM.

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