Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Match Date in Excel

Status
Not open for further replies.

HobbitK

Technical User
Jan 14, 2003
235
US
Hi Everyone ..
Brand new to VBA. I want to search for a specific date that is in a test spreadsheet. I put a command button on the form and then call an inputbox to gather the date to be found.
I am not on that PC right now but I think it was something like ..

Private Sub Command1_Click()
Dim dSearchDay as Date

dSearchDay = InputBox("Enter date to find")
End Sub

From here I cannot find a function to call that works with dates. I tried changing the cells formatting back to General. Atleast from there I thought I would be dealing with strings, but it did not provide the desired results.
Any guideance would be greatly appreciated, with as much explanation as you feel like including.
Michael
 
Keep the formatting as dates but instead, pick up the formatting from the data range you are about to search in

myDate = inputbox("Enter Date")

with sheets("Sheetname")
set fCell = .columns("A").find(format(myDate,.range("A2").numberformat),lookin:=xlvalues)
if not fCell is nothing then
'Date found
else
'Date Not Found
end if


Change A to be whatever column / range of columns you will be searching in Rgds
Geoff

Vah! Denuone Latine loquebar? Me ineptum. Interdum modo elabitur
 
Thaks for the help guys ... I will be able to try it in a few hours.
XLBO .. question ...
in your code you refer to fCode ...
Does that variable need to be dimensioned .. if so as what?
Or is it a VBA keyword?
Michael
 
thanx Rob - I always seem to forget to dim fCell - dunno why....must be 'cos I always use fCell in .FIND and it's almost become part of the function [ponder] Rgds
Geoff

Vah! Denuone Latine loquebar? Me ineptum. Interdum modo elabitur
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top