ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Return cursor to previous position (https://www.excelbanter.com/excel-discussion-misc-queries/138933-return-cursor-previous-position.html)

Kevryl

Return cursor to previous position
 
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.

Gary''s Student

Return cursor to previous position
 
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.
--
Gary''s Student - gsnu200715

Kevryl

Return cursor to previous position
 
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.

"Gary''s Student" wrote:

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.
--
Gary''s Student - gsnu200715


Gary''s Student

Return cursor to previous position
 
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.
--
Gary''s Student - gsnu200715

Kevryl

Return cursor to previous position
 
Thanks Garys Student. Looks easy enough now!
REgards, Kevryl

"Gary''s Student" wrote:

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.
--
Gary''s Student - gsnu200715



All times are GMT +1. The time now is 07:01 PM.

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