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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
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,214,653
Messages
6,120,752
Members
448,989
Latest member
mariah3

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