'Go Back' Button or Macro

lmpowell

New Member
Joined
Sep 20, 2006
Messages
5
Does anyone know of a back button in Excel 2003? I have several cells that are assigned a macro that will display a hidden worksheet. I want some kind of a 'back' feature that will return the user to the cell (which varies) that they were in before running the macro.

For example, macro A is assigned to cells A21, B24, and C143 in worksheet 1. If the user is in cell B24 of worksheet 1 and runs the macro which takes the user to worksheet 2, I want a 'back' feature (button or macro) that will return the user to cell B24 in worksheet 1 (or cell A21 if the user was in cell A21, etc).

Thanks!
LaDonn
 

Some videos you may like

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
Does anyone know of a back button in Excel 2003? I have several cells that are assigned a macro that will display a hidden worksheet. I want some kind of a 'back' feature that will return the user to the cell (which varies) that they were in before running the macro.

For example, macro A is assigned to cells A21, B24, and C143 in worksheet 1. If the user is in cell B24 of worksheet 1 and runs the macro which takes the user to worksheet 2, I want a 'back' feature (button or macro) that will return the user to cell B24 in worksheet 1 (or cell A21 if the user was in cell A21, etc).

Thanks!
LaDonn
Hi

If you don't use Select/Activate, it should stay in the same cell.
 

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,453
Hello lmpowell,
What jindon says is true and is ultimately the best way to try to code your routines if
possible, however if that's not possible for some reason (hard to imagine but what
the heck...) then here's a rather cheesy but effective way to get your 'back button'.

At the top of a standard module type (or paste) this.
Code:
Public SheetToReturnTo As Worksheet
Public CellToReturnTo As Range
Then in all your different macros, add this at the top of your code (or anywhere
before any activating/selecting takes place.)
Code:
Set SheetToReturnTo = ActiveSheet
Set CellToReturnTo = ActiveCell
Finally, for your back button's code you can use this.
Code:
Sub BackButton()
SheetToReturnTo.Select
CellToReturnTo.Select
Set SheetToReturnTo = Nothing
Set CellToReturnTo = Nothing
End Sub
Like I said, this should work fine but if you can I would seriously recommend
trying to code your routines without activating/selecting to begin with.
 

Watch MrExcel Video

Forum statistics

Threads
1,113,812
Messages
5,544,458
Members
410,613
Latest member
Texman
Top