Solved

EXCEL VBA Question

Posted on 2004-08-09
4
634 Views
Last Modified: 2012-05-05
Dear Experts,

In Excel97, I want a Calendar to pop-up when the user clicks on a cell in specific cell ranges. The user should only be able to enter dates chosen from the Calendar into the cell.

At the moment, I am using the following code. Form1 has the Calendar control on it. What this code does is that when an Active Cell is within the specified range, then when the user presses a shortcut, it runs the macro to pop-up the Calendar. This works fine, but I'd like the Calendar to pop-up when the user simply highlights a cell (makes a cell Active) in the specified ranges.

Thanks,
DocNash


Sub auto_open()
Dim KeyCells As String
KeyCells = "D3:D1000, E3:E1000, H3:H1000, J3:J1000, K3:K1000"
If Not Application.Intersect(ActiveCell, Range(KeyCells)) Is Nothing Then DoIt
End Sub

Sub DoIt()
UserForm1.Show
End Sub
0
Comment
Question by:DoctorNash
  • 3
4 Comments
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 75 total points
ID: 11751012
Hi,

You need to place your code presently in auto_open() in the Worksheet_SelectionChange() event.

Replacing "ActiveCell" with "Target", thus:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim KeyCells As String
KeyCells = "D3:D1000, E3:E1000, H3:H1000, J3:J1000, K3:K1000"
If Not Application.Intersect(Target, Range(KeyCells)) Is Nothing Then DoIt

End Sub


BFN,

fp.
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 11751016
PS. This area is probably the most appropriate for your question:

http://www.experts-exchange.com/Applications/MS_Office/Excel/
0
 

Author Comment

by:DoctorNash
ID: 11760469
Nice piece of work - thanks FanPages. By the way, it still seemed to work with 'ActiveCell' in the expression instead of 'Target'.
Regards,
DocNash
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 11762238
Hi,

Yes, ActiveCell would work if you had just selected a single cell, but if you had multiple cells selected, then Target would be the most appropriate.

Either way, glad you're happy with the solution.

BFN,

fp.
[ http://NigelLee.info ]
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Paint/Redraw window while dragging 16 83
using web browser with BING 40 132
TT Auto Dashboard 13 95
MS SQL Update query with connected table data 3 41
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question