Finding date/time greater than & less than, then 'get value'

TheRookie

New Member
Joined
Dec 22, 2018
Messages
12
Sigh... without confusing everyone with my 'non-working' code, here's what I am attempting to do:
1) I have a WS named "Washer_S25", among many others.
2) Every sheet has a date/time column B; using the format MM/DD/YY HH:MM
2B) A userform1 posts the date & time using the Now function.
3) Using helper cells, I have set up a date window and I want to find entries within that window.
3B) The "BeginDate1" (WS Cell L8) is using the =Now function and subtracting 1 day, and setting the time to 6AM. The EndDate1 (WS, cell L9) uses the same NOW and sets the time to 6AM. Same format as above; basically a 24 hour window.
4) I am trying to get UserForm2 (commandbutton click) to find entries greater than and less than BeginDate and EndDate.

After hours, and hours (forums and searching). nothing works, and gives errors. Is this enough to ask for some help with the VB Userform2 code? Or should I post those embarrassing stumbles?
 
Code:
Sub CellGrtrThan()
    Dim rng1st As Range, rng2nd As Range
    Dim BeginDate1 As Double, MsgBoxString As String
    Dim EndDate1 As Double, LastRow As Long
    Dim xRw As Long, cll As Range, NewCll As Range

    With Worksheets("Washer_S25")
        BeginDate1 = .Range("L8")
        EndDate1 = .Range("L9")

        LastRow = .Cells(Rows.Count, "B").End(xlUp).Row

        For xRw = 2 To LastRow
            If .Cells(xRw, "B") > BeginDate1 Then
                Set rng1st = .Cells(xRw, "B")
                Exit For
            End If
        Next

        For xRw = LastRow To 2 Step -1
            If .Cells(xRw, "B") < EndDate1 Then
                Set rng2nd = .Cells(xRw, "B")
                Exit For
            End If
        Next

        For Each NewCll In .Range(rng1st, rng2nd)
            MsgBoxString = MsgBoxString & NewCll.Offset(, -1).Value & vbNewLine
        Next

    End With

    MsgBox MsgBoxString
End Sub
 
Last edited:
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top