Worksheet_SelectionChange Question

A

a

Hello,

I've been trying to use the code for the individual worksheet for the
selection change:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Here is a small piece of the code

Set mc1 = Selection
MsgBox mc1.Address(RowAbsolute:=True, columnabsolute:=True,
ReferenceStyle:=xlR1C1)

My problem is that I want to get the address of the selection before the
user hits enter. Is there a way to do this?

Thanks in advance for any help that you can offer.

A
 
B

bigwheel

ActiveCell.Address will give you the information e.g.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("a1") = ActiveCell.Address
End Sub

A1 will change to show the selected cell's address
 
N

NickHK

You mean you want the "old" address, not the "new" address referred to by
Target.Address ?

Save cell or address to a module level variable in the SelectionChange event

Dim OldAddress As String

Private Sub Worksheet_Activate()
OldAddress = ActiveCell.Address
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
MsgBox "New address : " & Target.Address & vbNewLine & "Old address : " &
OldAddress
OldAddress = Target.Address
End Sub

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top