active cell reference

beans4brekkie1

New Member
Joined
Jul 31, 2009
Messages
6
Hi,
I was looking into how to reference the active cell and found a macro.

How do I then make this run within a cell

eg: I want cell A1 to always have the cell reference of the currently active (highlighted) cell. then i can use this to reference in other formulas.

How do i do this?

thanks

:confused:
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
You'd need code like this (in the sheet's code module - right-click on the sheet name and select View COde - paste in here):

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Range("A1").Value = ActiveCell.Address(False,False)

End Sub
 
Upvote 0
Try this: right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("A1").Value = Target.Address
End Sub
 
Upvote 0
Hi, again.

This works brilliantly - now to improve the macro...

if i select a merged cell - it is the range that comes up in cell A1 (ie B2:C3 for example). Is there a way to make it only come up with B2 (as this is surely the actual name for the cell once its merged?)

Thanks
 
Upvote 0
You just need this minor modification:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)


Range("A1").Value = ActiveCell.MergeArea(1).Address(False, False)

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,292
Members
452,902
Latest member
Knuddeluff

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