deedub84
asked on
Trigger excel vba routine only when cursor leaves range?
Hi Experts,
I'm creating a spreadsheet that has a number of input ranges that the user will need to fill in.
For each of these ranges, I'd like to trigger a routine that runs only when the cursor moves outside that particluar range, rather than on every change within each range.
Not sure how I might accomplish that.
Thanks,
Deedub84
I'm creating a spreadsheet that has a number of input ranges that the user will need to fill in.
For each of these ranges, I'd like to trigger a routine that runs only when the cursor moves outside that particluar range, rather than on every change within each range.
Not sure how I might accomplish that.
Thanks,
Deedub84
When you say "cursor" do you mean the mouse cursor or the cell focus? I just want to be sure I understand exactly what you want.
ASKER
You're right, the cell focus. Thanks for clarifying...
You might try something like this. This will not work the first time the worksheet is opened. Thereafter it will work. This particular routine checks for F12
Public ptarget As Range
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ptarget Is Nothing Then
Set ptarget = Target
Else
If ptarget.Address = Range("F12").Address Then Call abc
Set ptarget = Target
End If
End Sub
Sub abc()
'Your processing goes here
End Sub
Here's a solution that might work for you. Try it out.
deedub84-Trigger-excel-vba-routi.zip
deedub84-Trigger-excel-vba-routi.zip
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
NFP:
You might also want:
and something in Workbook_Open to check if that sheet is active, and if so assign the active cell.
You might also want:
Private Sub Worksheet_Activate()
Set pTarget = ActiveCell
End Sub
and something in Workbook_Open to check if that sheet is active, and if so assign the active cell.
ASKER
Perfect thanks!