Sgt Rock
10-06-2012, 12:31 PM
Seeking assistance with interpretation of code to retrun cursor to it's previous location.
Code works sometimes and sometimes not. Doesn't seem to work when first opening the workbook its cotained in. Maybe something needs to be cleared first? To run the code I've assigned an icon to it in the ribbon. Cannot recall where I found the code but it's just a few lines lone. Also not sure why one part is inserted into a module while in the VBE, and the other part of the code is inserted on the worksheet, by right clicking worksheet, view code, and pasting code there. Thanks in advance! I'm new at VBA and still learning each day.
Code inserted via "insert module" in VBE
Option Explicit
Public r As Range
Public oldr As Range
Sub GOBACK()
If oldr Is Nothing Then
Else
oldr.Select
End If
End Sub
Code inserted via the worksheet "view code"
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set oldr = r
Set r = Target
End Sub
Code works sometimes and sometimes not. Doesn't seem to work when first opening the workbook its cotained in. Maybe something needs to be cleared first? To run the code I've assigned an icon to it in the ribbon. Cannot recall where I found the code but it's just a few lines lone. Also not sure why one part is inserted into a module while in the VBE, and the other part of the code is inserted on the worksheet, by right clicking worksheet, view code, and pasting code there. Thanks in advance! I'm new at VBA and still learning each day.
Code inserted via "insert module" in VBE
Option Explicit
Public r As Range
Public oldr As Range
Sub GOBACK()
If oldr Is Nothing Then
Else
oldr.Select
End If
End Sub
Code inserted via the worksheet "view code"
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set oldr = r
Set r = Target
End Sub