macro to find date entered by user in a range

Alwina

Board Regular
Joined
Oct 3, 2013
Messages
61
Hi there

I am using the following macro to find the date entered in e2 in a range a:a the date in both cell and column is in dd/mm/yyyy format. When i run the macro I get a compile error: Cant find project or library and TRIM is highlighted. Here is the code i am using.


Code:
Sub Find_First()
    Dim FindString As String
    Dim Rng As Range
    FindString = Sheets("Bookings").Range("e2").Value
    If Trim(FindString) <> "" Then
        With Sheets("Bookings").Range("A:A")
            Set Rng = .Find(What:=FindString, _
                            After:=.Cells(.Cells.Count), _
                            LookIn:=xlValues, _
                            LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlNext, _
                            MatchCase:=False)
            If Not Rng Is Nothing Then
                Application.Goto Rng, True
            Else
                MsgBox "Nothing found"
            End If
        End With
    End If
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Works for me except you will need to change

Code:
Dim FindString As String

to

Code:
Dim FindString As Date

if its looking for true dates. I run it here and it goes to first date in column A matching E2.
 
Upvote 0
You will need to open the VBA window then tools-references. Usually there are 5 ticked I believe. Mine has VBA ticked, MS Excel Object Library, OLE Automation, MS Office Object Library and MS Forms Object Library. Have a look to see if you have any marked as missing too.
 
Upvote 0
Hi All,

With the same example, I have Sheet 1 and Sheet 2, using this code to search a date from one sheet to another, but after I get my results, I want to add a formula in some of the cells in the same row, like If I found the value in A10 in A:A, I want to add formulas in B10, D10, E10. Can anyone give me a code how to move cells after finding a search value.
 
Upvote 0

Forum statistics

Threads
1,213,491
Messages
6,113,963
Members
448,536
Latest member
CantExcel123

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