Return cursor to previous position

K

Kevryl

I'm using Excel 2000. I'm sure that in earlier versions there was a function
key that returned the cursor to the previous position. I have always
remembered it being or involving the F5 key, but the nearest I can get is a
selection box. The "Help" file offers nothing. Its such a simple function it
has to exist! Can someone help?

I'm looking for this as an alternative because Excel is incapable of
creating a relative range name during a macro. Even clicking the "relative"
option still results in recording an absolute reference to the cell
referenced during macro creation, rather than the keystrokes used to produce
it.
 
G

Gary''s Student

Hi Kevryl:

You can create this feature within a single sheet:

In worksheet code enter:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set oldr = r
Set r = Target
End Sub


In a standard module enter:

Public r As Range
Public oldr As Range
Sub goback()
If oldr Is Nothing Then
Else
oldr.Select
End If
End Sub


and assign a shortcut like CNTRL+e to goback. As you either click or arrow
around the sheet, CNTRL+e will return you to the previous selection.


REMEMBER: this will work only within a single sheet.
 
K

Kevryl

Thanks Gary's Student.

You're speaking a bit above my level. Is this 2 ways of doing the same thing
or do both the worksheet code bit and the standard module bit have to be done?
Where do I go to enter worksheet code? Is that the X symbol to the left of
"File" right click/View code routine?
Standard module: Is that the modules where macros are recorded into? I've
done quite a bit of manipulation in there with amending copied macros.
 
G

Gary''s Student

We need to do both:

First insert the module code:

1. ALT-F11 brings up the VBE window
2. ALT-I
ALT-M opens a fresh module
3. paste this stuff in and close the VBE window:

Public r As Range
Public oldr As Range
Sub goback()
If oldr Is Nothing Then
Else
oldr.Select
End If
End Sub


Next insert the worksheet code:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste this stuff in and close the VBE window:


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set oldr = r
Set r = Target
End Sub


You can then assign the shortcut to goback.


Note that none of this is necesary if you are navagating a single worksheet
using hyperlinks. You can always return from a hyperlink with the Back
button.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top