+ Reply to Thread
Results 1 to 13 of 13

date selection in a cell?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-29-2005
    Location
    Singapore
    MS-Off Ver
    2007
    Posts
    253

    Question date selection in a cell?

    Hi,

    Is it possible to click on a cell and a monthly calendar pops up for you to select a date to input? The output will be just the DD/MM/YY format.

    Regards,
    Lewis

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    re: date selection in a cell?

    I attached a working example of how to employ a pop-up calendar.
    Of course, the file DOES have macros.

    To see the demo...
    Dbl-click a cell in Col_A
    A pop-up calendar will display
    Select and click a date to have it entered in the active cell
    Click Cancel or Press ESC to close the calendar without entering a date.

    Sheet1 has this VBA Code:

    Option Explicit
    
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        If Not Intersect(ActiveCell, [A:A]) Is Nothing Then
            PopUpCalEntry ActiveCell
        End If
    End Sub
    The general module contains this code:
    Option Explicit
    
    Sub PopUpCalEntry(cCell As Range)
        Dim newDate As String
        Load frmCal
    
        newDate = Format(Date, "mm/dd/yyyy")
    
        frmCal.Calendar1.Value = newDate
        frmCal.Show
    End Sub

    The Calendar1 form has this VBA code:

    Option Explicit
    
    Private Sub Calendar1_Click()
        On Error GoTo errTrap
        With ActiveCell
            .Value = Calendar1.Value
            .NumberFormat = "mm/dd/yyyy"
        End With
    errTrap:
        Unload Me
    End Sub
    
    Private Sub cmdCancel_Click()
        Unload Me
    End Sub
    Is that something you can work with?
    Attached Files Attached Files
    Last edited by Ron Coderre; 12-30-2009 at 11:33 PM.
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Forum Contributor
    Join Date
    07-29-2005
    Location
    Singapore
    MS-Off Ver
    2007
    Posts
    253

    re: date selection in a cell?

    er....how do I put the codes in? I'm not familiar with Macros..I know where to open the editor but not sure where to copy to.

  4. #4
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    re: date selection in a cell?

    take a few moments to study Ron's post. He says it quite clearly:

    Sheet1 has this VBA Code:
    and

    The Calendar1 form has this VBA code:
    and

    The general module contains this code:
    Then open the attached example file, hit ALT-F11 to open the VBE and click your way through the code in the Sheet1, Module1 and Form modules to see where the code is.

  5. #5
    Forum Contributor
    Join Date
    07-29-2005
    Location
    Singapore
    MS-Off Ver
    2007
    Posts
    253

    re: date selection in a cell?

    Oh, sorry, I missed out the attached file.

    The calendar is great. but when I double click on the yellow column, I can't choose the dates without pressing ESC or clicking on another cell. Is there a command line that controls this action?

    May I know what does [A:A] means? Can I change to specific cells like M9:M17, M18:M22, etc?
    I tried [M9:M17], [M18:M22], but [M9:M17],[M18:M22] are not working. Removing [M18:M22], [M9:M17] will work.

    How do I put the calendar into my excel file?
    Last edited by Lewis Koh; 01-04-2010 at 01:58 AM.

  6. #6
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    re: date selection in a cell?

    Quote Originally Posted by Lewis Koh View Post
    Oh, sorry, I missed out the attached file.

    The calendar is great. but when I double click on the yellow column, I can't choose the dates without pressing ESC or clicking on another cell. Is there a command line that controls this action?

    May I know what does [A:A] means? Can I change to specific cells like M9:M17, M18:M22, etc?
    I tried [M9:M17], [M18:M22], but [M9:M17],[M18:M22] are not working. Removing [M18:M22], [M9:M17] will work.

    How do I put the calendar into my excel file?


    1) After dbl-clicking a Col_A cell, the Calendar form pops up.
    •Click a date...it will be entered in the active cell and the form will close
    or
    •Click the Cancel button to just close the form

    2)[A:A] designates that all Col_A cells, when dbl-clicked, engage the form.

    3)To only use M9:M17 and M18:M22(...which is really M9:M22, right?)
    Change the Sheet1 code to:

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        If Not Intersect(ActiveCell, [M9:M22]) Is Nothing Then
            PopUpCalEntry ActiveCell
        End If
    End Sub
    4)To use the pop-up calendar functionality in your workbook....
    •Open the demo workbook AND your workbook
    •[Alt]-[F11] to open the VBA editor
    From the VBA Project window
    •Drag the frmCal from the demo to your workbook
    •Drag Module1 from the demo to your workbook
    •Dbl-Click the demo Sheet1 to see the code (make sure it's edited for M9:M22)
    •Copy all of the Sheet1 code
    •Dbl-Click your sheet to see the code
    •Paste the demo Sheet1 code into your sheet module
    Done...your workbook should now display the pop-up when a cell in M9:M22 is dbl-clicked.

  7. #7
    Forum Contributor
    Join Date
    07-29-2005
    Location
    Singapore
    MS-Off Ver
    2007
    Posts
    253

    Re: date selection in a cell?

    1) After dbl-clicking a Col_A cell, the Calendar form pops up.
    •Click a date...it will be entered in the active cell and the form will close
    or
    •Click the Cancel button to just close the form

    I can't choose the date after the pop-up. I had to click on another cell to sort of activate the calendar pop-up before I can choose a date.

    2)[A:A] designates that all Col_A cells, when dbl-clicked, engage the form.
    Does that mean if I wanted column M to be the input column, I should change to [M:M]?

    3)To only use M9:M17 and M18:M22(...which is really M9:M22, right?)
    Change the Sheet1 code to:

    Oh sorry, I had other info on M18 so the column should be M9:M17 and M19:M22. I had a lot of other rows on column M that need not have date input, thus I'm wondering if I could set the pop-up on multiple rows with breaks in between them..

  8. #8
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: date selection in a cell?

    1) I don't understand why you are experiencing the odd calendar behavior.
    I cannot replicate it on Excel 2003. When I dbl-click a target cell, the
    calendar pops up. When I click on a date in the calendar, the date is posted
    in the active cell and the form closes.

    2) Yes, you would refer to Col_M by replaceing [A:A] with [M:M].

    3) To refer to M9:M17, M19:M22...
    •Select those two clusters of cells.
    •Assign a name to them (I used MyDateCells)
    •Use the below code in the sheet module:

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        If Not Intersect(ActiveCell, [MyDateCells]) Is Nothing Then
            PopUpCalEntry ActiveCell
        End If
    End Sub

  9. #9
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: date selection in a cell?

    Oh, could it be because I am using Excel 2000?
    Could you please update your profile? The version information keeps experts from heading off in a direction that may not work in a specific version.

    If you are asking for a solution for a version that differs from your regular version listed in the profile, please make sure to mention it.

  10. #10
    Forum Contributor
    Join Date
    07-29-2005
    Location
    Singapore
    MS-Off Ver
    2007
    Posts
    253

    Re: date selection in a cell?

    Oh, I'm sorry, my office excel is 2000 but my home is 2003. I just realized it. I'll change my version since I am using it for work most of the time.

    Does that mean 2000 and 2003 behave differently?

  11. #11
    Registered User
    Join Date
    03-20-2011
    Location
    toronto canada
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: date selection in a cell?

    Hello everyone and thanks in advance for any assistance.
    The function works well, however, in my case after the double click to enable the calendar, I must first either
    press ESC or change the active cell from the double click cell that initiated the calendar.

    Then the function will work as expected? Any ideas how to resolve this annoyance? I am using Excel 2007. Perhaps some settings are not correct, but I cannot think what those settings may be.
    Thanks again,
    Tom

  12. #12
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: date selection in a cell?

    tepraco,

    please take a moment to read the forum rules and then start your own question. Link to this one if you feel it helps explain your issue.

    cheers

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1