Macro to link selected cell to most recently edited cell.

Jaegan

New Member
Joined
Mar 19, 2012
Messages
3
Hey folks. Looking to make a very basic macro, but my VBA skills are below basic!

Essentially, I want a macro that when used will set the currently selected cell to reference to the cell I most recently edited. So for example, after I complete the sum in C9, I want to go to cell A1, run my macro, and have A1 generate the formula linking it to cell C9.

[TABLE="width: 500"]
<tbody>[TR]
[TD]=C9
[/TD]
[TD][/TD]
[TD]5
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]4
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]=SUM(C1:C3)
[/TD]
[/TR]
</tbody>[/TABLE]


The main challenge I think will be trying to get the references to work across tabs (e.g. adding in the !sheet references when needed). Any pointers you can provide would be much appreciated!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
In every worksheet, include the follow event macro in the worksheet code area:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    LastChanged = "=" & Target.Parent.Name & "!" & Target.Address
End Sub
In a standard module include the following:

Code:
Public LastChanged As String
Sub CaptureLastChanged()
    Application.EnableEvents = False
        ActiveCell.Formula = LastChanged
    Application.EnableEvents = True
End Sub

So after you have done some edits, run CaptureLastChanged to settup the activecell
 
Upvote 0
Thanks a bunch. I will fiddle with this a bit later today and let you know if I run into any issues.

It sounds like there is no way around having to include the macro event in each tab if I want this to work. Would I be correct that even if we were to limit the macro functionality to only link to a cell within a specific tab ( no cross tab linking), we would still need the event macro in order to flag the most recently edited cell?
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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