Consulting

Results 1 to 3 of 3

Thread: Solved: Open User Form in specified range

  1. #1

    Solved: Open User Form in specified range

    Hi All,

    I've attached a test workbook with a form that I'm using to pick the time/date and this is the the code using to open the form in the range B3:E18.
    [vba]Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    If Not Application.Intersect(Target, Range("B3:E18")) Is Nothing Then
    Datetime1.Show
    End If
    [/vba]
    I want the form to to open when you double click the left mouse botton or hit the enter the botton in the range B3:E18 because at the moment it's annoying that the form opens when click in the range by mistake.


    P.S. Feel free to play around with the form because I feel it can be made to work better.

    Many thanks

    Attachment 8687

  2. #2
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    I would stick with the double-click event, rather than trapping the Enter key:
    [VBA]Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Application.Intersect(Target, Range("B3:E18")) Is Nothing Then
    Cancel = True
    Datetime1.Show
    End If
    End Sub
    [/VBA]

    HTH
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Thank you Rory,

    the code works well and I think you are right about using only the double-
    click option.

    rds

Posting Permissions

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