Issue using Find function to locate date

txaggies2004

New Member
Joined
Jun 19, 2011
Messages
2
Hi,

I'm relatively new to programming macros for excel and I'm having issues with one I create to find a user specific date and then copy a range of cells to another sheet. The issue I'm having is when the original date to find is entered in only select dates will be found. Examples of dates it can find would be 6/2/2011 and 6/9/2011. It is unable to find dates with either a double digit month or day, ex. 6/15/2011. Has anyone encountered this problem before? Any help you could offer would be appreciated.

Thanks

Here is the code I am using. Any suggestions on ways to increase efficency would be appreciated as well.

Code:
Sub DateSearch()
    Dim Found As Range
    Dim wsI As Worksheet
    Dim wsO As Worksheet
    Set wsI = Sheets("Bar Inventory")
    Set wsO = Sheets("Final Print")
    On Error GoTo Err_Execute
 
    Dim Message, Title, MyValue
    Message = "Enter Inventory Date"
    Title = "Search"
    MyValue = InputBox(Message, Title)
 
    If Len(Trim(MyValue)) = 0 Then Exit Sub
 
    If Len(MyValue) < 8 Or Len(MyValue) > 10 Then
        MsgBox "Please enter date in proper format. (Ex. 1/1/2011)"
        Exit Sub
    End If
 
    wsO.Range("E:O").ClearContents
 
    Set Found = Rows(2).Find(MyValue, Range("A2"), xlValues, xlWhole, xlByColumns, xlNext, False, False)
    Found.EntireColumn.Select
    Selection.Copy
 
    wsO.Range("E:O").PasteSpecial (xlPasteValuesAndNumberFormats)
 
    Application.CutCopyMode = False
 
    MsgBox "Inventory for " & MyValue & " has been copied!"
 
    wsO.Select
 
    Exit Sub
 
Err_Execute:
    MsgBox "An error occurred."
 
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
If some or all of the dates are entered as text rather than dates, the user must input the "date" exactly as it appears in the text entry or if will not be found. The text 06/05/2011 is different than text 6/5/2011.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,855
Members
452,948
Latest member
UsmanAli786

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