Hello, I have been working on this Function for awhile and can't seem to get it to work, nor have I been able to find any posts that have helped solve my particular issue.
What I am trying to accomplish is to be able to find dates that could be in any of the columns A:G from Sheet4, using the Date value that is one cell to the left of my active cell in Sheet9.
The below code is what I have so far that worked when I had static values like (1/1/16) in my search, but does not work now that I am trying to use a variable. On the 2nd line of my with statement I just had .Select when I had static search terms and it worked, but once I added a variable I got the error "Object variable or With Block not Set", so I added ActiveCell in front of it, but that now just makes it pick whatever cell my cursor happens to be in. Any help on this would be greatly appreciated.
What I am trying to accomplish is to be able to find dates that could be in any of the columns A:G from Sheet4, using the Date value that is one cell to the left of my active cell in Sheet9.
The below code is what I have so far that worked when I had static values like (1/1/16) in my search, but does not work now that I am trying to use a variable. On the 2nd line of my with statement I just had .Select when I had static search terms and it worked, but once I added a variable I got the error "Object variable or With Block not Set", so I added ActiveCell in front of it, but that now just makes it pick whatever cell my cursor happens to be in. Any help on this would be greatly appreciated.
Code:
Sub test()
Dim rFoundCell As Range
Dim vDate As Variant
Dim Expense As Worksheet
Dim Data As Worksheet
Set Expense = Sheet9
Set Data = Sheet4
Set rFoundCell = Range("A1")
Set vDate = ActiveCell.Offset(0, -1)
Set rFoundCell = Data.Range("A:G").find(What:=vDate, After:=rFoundCell, _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
Sheet4.Activate
With rFoundCell
ActiveCell.Select
ActiveCell.Offset(1, 0).Copy
Sheets("Expense Data").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Transpose:=True
ActiveCell.Offset(1, 0).Select
End With
/Code