Running a Macro when a single cell is selected

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 ?
 
D

Dave Peterson

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.
 
G

Guest

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
 

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