View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Help needed starting a macro

Right click on the sheet tab and select view code.

In the resulting module, at the top, in the left dropdown, select Worksheet
and in the right dropdown, select SelectionChange

This puts in a declaration for the selectionchange event

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub

Target is a range reference to the cell selected by the user using the
methods you describe (or any other way they get there).

You can then test if Target is in your range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
if target.count 1 then exit sub
if not intersect(target, Range("A1:B50")) is nothing then
' selected cell is in the range A1:B50

End if
End Sub

If your code will select another cell inside that range, then you would need
to turn events off (and back on again when done) so you don't get recursive
calls to the event.

--
Regards,
Tom Ogilvy

End Sub
"Simon Lloyd " wrote in message
...
I want too start a macro when a cell in a certain range is left clicked
or selected by navigating to it using the arrow keys.....i.e if cell is
selected in range xx:yy then run macro or when cell in range is
highlighted by arrow keys.im new to VBA so an idiots guide on how to do
this would be very well apreciated!

Thanks in advance!
Simon


---
Message posted from http://www.ExcelForum.com/