Excel VBA how to search data from a date

S5ON3E

New Member
Joined
May 11, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm trying to do a research in a userform from a date, I can search from a word but can't figure out how to do it from a date. Like here in the picture, from the textbox I have to enter the date of birth then click search and then the looked for data would go in respective textbox. Can someone help me? Thank you

F5201D67-56EE-49E8-84F8-EAFD0248F0B5.png
 
For just the find the date part see if the below helps. Most people seem to use the Find function but it has quite a heavy reliance on the date format, this option using "Match" is more forgiving.
Not sure what you want to do if you have multiple rows with the same date though.

VBA Code:
Sub FindDate_GetRow()

    Dim Sht As Worksheet
    Dim rowDOB As Long
    Dim rngDOB As Range
  
    Set Sht = Worksheets("Sheet1")      '<--- Change this to your worksheet name
    Set rngDOB = Sht.Range("D:D")
  
    With Application
        ' <--- Change this to use your text box values in DateSerial(yyyy, mm, dd)
        rowDOB = .IfError(.Match(CLng(DateSerial(2022, 5, 12)), rngDOB, 0), 0)
    End With
  
    If rowDOB = 0 Then
        MsgBox "Date not found"
    Else
        MsgBox "Drivers Permit: " & Sht.Range("H" & rowDOB).Value
    End If

End Sub
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Well I'm back I never like giving up.
When we look on the sheet how will we see the Date?

Will it be: 5/12/2022
Or will it be 5-12-2022
Or show me how it will look
This would be May 12 2022 in my example

But again have users enter dates can be tricky when then you want to search for date.
Easy want is to select date in Combobox or enter entire date in one TextBox
 
Upvote 0

Forum statistics

Threads
1,223,632
Messages
6,173,467
Members
452,516
Latest member
archcalx

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