+ Reply to Thread
Results 1 to 9 of 9

Date Picker from user form

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-05-2008
    Posts
    116

    Date Picker from user form

    Hi everyone

    I have a calender in userform1, and I want to be able to click on a cell that is formatted to date, then for the calender to appear, then me select a date and for it tobe placed into the selected cell, would anyone be able to help me this code please?

    Many Thanks

    Denzil

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You can display the form like this

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Target.Count > 1 Then Exit Sub
        If Target.Address= "$A$1" Then frmDTP.Show
     End Sub
    This line will add the date

    ActiveCell.Value=Me.DatePicker1.Value
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    02-05-2008
    Posts
    116
    Hi Roy

    Thank you very much for your reply, do I just put your code in the the worksheet thats relevent as you sent it to me?

    Right click on the tab and veiw code and place it in there?

    Many thanks again

    Denzil

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    That's correct for the worksheet, the other line needs a button on the form

  5. #5
    Forum Contributor
    Join Date
    02-05-2008
    Posts
    116
    Hi Roy

    Thanks again for your quick response, ive bin playin with the worksheet, and havent had any joy, Ive noticed in the code it has A1, could that be changed to any cell that is date formatted?
    I ran tha code selecting A1 and it has an error and the code stops at the line [QUOTE]If Target.Address = "$A$1" Then formdtp.Show

    Any ideas? have I done something wrong?

    Many Thanks Again

    Denzil

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You need to edit the code to contain the name of your userform.
    This will check if the cell contains a date or is formatted as a date

    Option Explicit
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Target.NumberFormat = "m/d" Or IsDate(Target) Then UserForm1.Show
    End Sub
    Change the number format to suit your needs

+ 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