Consulting

Results 1 to 3 of 3

Thread: Setting date picker to certain columns only

  1. #1
    VBAX Contributor
    Joined
    Jul 2011
    Location
    Manchester
    Posts
    142
    Location

    Setting date picker to certain columns only

    I use a date picker on most of my workbooks so users enterthe date in a correct format but at the moment it works by double clicking onany cell on a work sheet.

    Can anyone show me how to restrict this to ranges in certaincolumns on please?
    In the attached example it would be A2:A100 and D2100 only

    Thanks as always
    Mykal
    Attached Files Attached Files

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Probably something like this

    Option Explicit
    
    Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        Dim myDate As Date
        Dim r As Range
        
        Set r = Target.Cells(1, 1)
        
        If Intersect(r, Range("A2:A100")) Is Nothing And Intersect(r, Range("D2:D100")) Is Nothing Then Exit Sub
    
    
        Set clsCal = New ClsCalendar
        FormPicker.Show
        myDate = clsCal.SelectedDate
    
        If myDate > 0 Then  'Check to see if it was cancelled
            Application.EnableEvents = False
            Target.Value = clsCal.SelectedDate
    
    Application.EnableEvents = True
    End If
    Finally: Set clsCal = Nothing Cancel = True End Sub
    Last edited by Paul_Hossler; 02-26-2019 at 07:21 AM. Reason: Added Application.EnableEvents = False
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Contributor
    Joined
    Jul 2011
    Location
    Manchester
    Posts
    142
    Location
    Hi Paul
    This worked perfectly and much easier to restrict it tocertain ranges rather than the whole sheet. I have played a few times but couldn’t figureit out.!
    Thank you very much for your help and quick reply, alwaysappreciate any help you guys give.
    Barry

Tags for this Thread

Posting Permissions

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