How to refer back to previously populated cell during change event

DwinZly

Board Regular
Joined
Oct 26, 2009
Messages
56
Hello,

I have a basic change event macro here:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Selection.Count = 1 Then
If Not Intersect(Target, Me.Range("B3:B300")) Is Nothing Then AutoFill
End If


End Sub

The problem is that I want to be able to refer back to the cell that was just changed in my AutoFill macro. For instance, if someone changes the value in cell B5, they can either hit enter (to B6) or arrow over (to C5) and the final destination of the cursor will be different each time. Therefore I cannot accurately predict what the cell was that was just changed. Unfortunately the change event does not trigger the macro until the cursor has moved so I can't use activecell commands. Is there a way to run the macro after the value changes but before the cursor moves?

Thanks
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
The cell that was changed is Target
HTH
 
Upvote 0
The problem is that I want to be able to refer back to the cell that was just changed in my AutoFill macro. For instance, if someone changes the value in cell B5, they can either hit enter (to B6) or arrow over (to C5) and the final destination of the cursor will be different each time. Therefore I cannot accurately predict what the cell was that was just changed. Unfortunately the change event does not trigger the macro until the cursor has moved so I can't use activecell commands. Is there a way to run the macro after the value changes but before the cursor moves?
Create a module level global variable (Dim it at the top of the code module outside of any procedures) as a Range variable and set the variable to reference the Target in the SelectChange event procedure. That way, you can use the variable inside of the Change event procedure (but do not Dim it inside the Change event procedure, only Dim it outside of any procedures at the top of the module).
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top