Running a Macro when a single cell is selected

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello, I've tried to do this a number of ways, I am trying to trigger a macro
when a certain cell is selected. My particular application is, when "J10" is
selected, I want to be able to have my calendar macro run so the person can
select a date and have that cell filled with the selected date.

Any suggestions ?
 
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

if target.cells.count > 1 then exit sub
if intersect(target, me.range("j10")) is nothing then exit sub

Call yourmacrotoshowthecalendarhere

End Sub

This is a worksheet event. Rightclick on the worksheet tab that should have
this behavior and select view code. Then paste the code into that code window.
 
In the worksheet's SelectionChange event do something along the following
lines, the example below uses cell B2 as the trigger cell:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim strAddress As String

strAddress = ActiveCell.Address

If strAddress = "$B$2" Then
" Put the calendar activation code right here."
Else
Exit Sub
End If

End Sub
 
Back
Top