You are here:

Excel/Need help in excel

Advertisement


Question
Hi,

I am rajeev and I need your help in the excel 2010 which I am using. Actually, excel 2010 does not support calendar.ocx so I tried to use the data picker, but its not working. Can you please look at the below function and let me know where I am wrong?

Also, just to give you background, I actually need the calendar to come only if I click any of the cells from F22 to F71 and if the value in cell E22 to E71 is Date.

Private Sub DTPicker1_Click()
If Not rng Is Nothing Then
rng.Value = DTPicker1.Value
End If
DTPicker1.Visible = False
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim r As Range
If bBlockEvents Then Exit Sub
If DTPicker1.Visible Then
 cnt = cnt + 1
 If cnt >= 2 Then DTPicker1.Visible = False
End If

If Target.Count > 1 Then Exit Sub
Set r = Range("F22:F71")  ' change the range to what you want

If Not Intersect(Target, r) Is Nothing Then
       Set rng = Target
  If rng.Offset(0, -1) = "Date" Then
       DTPicker1.Left = Target.Left + Target.Width - DTPicker1.Width
       DTPicker1.Top = Target.Top + Target.Height
       DTPicker1.Value = Range("E2")
       DTPicker1.Visible = True

  End If
End If
End Sub

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim r As Range

If Target.Count > 1 Then Exit Sub
Set r = Range("F22:F71")  ' change the range to what you want

If Not Intersect(Target, r) Is Nothing Then
       Set rng = Target
    If Len(Trim(Target)) > 0 And IsDate(Target) Then
       DTPicker1.Left = Target.Left + Target.Width - DTPicker1.Width
       DTPicker1.Top = Target.Top + Target.Height
       DTPicker1.Visible = True
       Cancel = True  ' so  you don't go into edit mode


    End If
End If
End Sub

Answer
Hi Rajeev,

Can you tell me how you got the date picker into the sheet. Possibly share the file if you can. I'm guessing there should be an easier way for you to pick dates depending on the kind of requirements you have.

You can either share a link to your file or send me the file by email (gulshanrajpurswani@gmail.com). Please mention AllExperts in the subject line.

Thanks,
Gulshan.
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


GULSHAN PURSWANI

Expertise

I can answer questions related to the following topics: 1. MS Excel - Creating and Linking Formulae, Running Pivot Tables, Vlookup etc. 2. Macros / VBA - Creating Macros to do specific jobs. Importing / Exporting / Validating Data in excel through Macros.

Experience

I've been working on excel for over 10 years and on VBA macros for over 3 years now.

Education/Credentials
Bachelor of Commerce, Chartered Accountant from The Institute of Chartered Accountants of India

©2016 About.com. All rights reserved.