Results 1 to 3 of 3
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    find between two dates (2000)

    admit have in userform textbox1=01/06/2008 and texbox2=30/06/2008 in column A have 02/06/2008, 05/07/2008,28/06/2008... ecc
    how to find in column A if a date in in the range from the 2 textbox and show msgbox "date present in range 01/06/2008-30/06/2008"
    How to?
    In this case 02/06/2008 and 2806/2008 sre in the range...

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: find between two dates (2000)

    I presume that you will have on the userform a button called CommandButton1 to click after the dates are entered.

    <pre>Option Explicit
    Private Sub CommandButton1_Click()
    Dim dMin As Date
    Dim dMax As Date
    Dim rngA As Range
    Dim rCell As Range
    Dim wks As Worksheet
    Dim bFound As Boolean

    bFound = False
    dMin = DateValue(Me.TextBox1.Value)
    dMax = DateValue(Me.TextBox2.Value)
    Set wks = ActiveSheet
    With wks
    Set rngA = .Range(.Range("A1"), _
    .Cells(.Rows.Count, 1).End(xlUp))
    For Each rCell In rngA
    If rCell >= dMin And rCell <= dMax Then
    bFound = True
    Exit For
    End If
    Next
    End With
    If bFound Then
    MsgBox "Date present in range " & _
    Format(dMin, "dd/mm/yyyy") & "-" & _
    Format(dMax, "dd/mm/yyyy")
    Else
    MsgBox "No Dates in range " & _
    Format(dMin, "dd/mm/yyyy") & "-" & _
    Format(dMax, "dd/mm/yyyy")
    End If
    Set wks = Nothing
    End Sub</pre>


    Steve

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: find between two dates (2000)

    PERFECT!
    Yes i use exactly a CommandButton1 to test the range!
    Tks.

Posting Permissions

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