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.
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