VBA Excel Detect when cell selected

gbergsma
gbergsma used Ask the Experts™
on
Hi,

Is there a way in VBA to detect when the user has clicked on (ie. selected) a cell in an Excel worksheet? I want to be able to automatically populate a list based on the contents of the selected cell, rather then having the user click a button to do so

Thanks

Bergsy
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010
Commented:
gbergsma said:
>>Is there a way in VBA to detect when the user has clicked on (ie. selected) a cell in an Excel worksheet?

Yes, the worksheet object has a SelectionChange event, for which the Target returns a range object containing
the currently selected cell(s).

>>I want to be able to automatically populate a list based on the contents of the selected cell, rather then
>>having the user click a button to do so

Do you perhaps me the ActiveCell?  More than one cell can be selected at any one time, but only one cell can
be the ActiveCell...
Commented:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
MsgBox "You selected cell(" & Target.Row & "," & Target.Column & ")"
End Sub
Top Expert 2010

Commented:
learn,

Yes, but that returns the info for the top-left cell in the first area selected if the current selection holds >1 cell.

That might not be what is required here.

Patrick

Author

Commented:
Thanks everyone

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial