Macro to start when cell selected

G

Guest

I have the following macro that I want to open when the user clicks cell b2,
which launches the calendar, then after they have selected the date and move
out of that cell the calendar closes.

Any help would be great

Here is the macro I want to start,

Sub OpenCalendar()

End Sub
 
R

Ron de Bruin

Hi

Copy this code in the Worksheet module:
Right click on the sheet tab and choose view code.
Paste the code in there and press Alt-Q to go back to Excel.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Range("B2"), Target) Is Nothing Then
Call OpenCalendar
End If
End Sub

When you select B2 the macro OpenCalendar will run in the normal module
 
G

Guest

Everything works except that when the calendar pops up and I click on date
it will not enter the date. How can I e-mail you the actual spreadsheet so
you can look at it and see what I have done wrong??
 
G

Guest

I tried your code example, but I have 2 problems with it,

1. I need it to work with a sheet protected, which it would not do I got an
error message, is there a way to do this?

2. I need it to be a little smaller and not pop up right under the selected
cell, is there a way to move it?

If you can resolve these 2 issues your code is great.
 
R

Ron de Bruin

Unlock the Date cells before you protect the sheet

Or protect you sheet with code
Copy this in the thisworkbook module and save /close/reopen the workbook

Private Sub Workbook_Open()
With Worksheets("sheet1")
.Protect Password:="hi", userinterfaceonly:=True
End With
End Sub

2. I need it to be a little smaller

Yes
Right click the control and look in Format object
and not pop up right under the selected cell, is there a way to move it?

Change the code

Calendar1.Left = Target.Left + Target.Width - Calendar1.Width
Calendar1.Top = Target.Top + Target.Height
 

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