Folks,
I've been using a macro for quite some time to copy data based upon a single lookup value (Employee Name). This works great when the source data has fixed columns for the data needed. However, I'm now facing a challenge of needing to look up data not just based on the name, but also on the date that the event happened.
Here is the code I have been using:
What I need is a way to take this code, or something similar, and add in a second search to find the matching Date. The Date will be in Row 4 on the Data (Source) sheet, and will be in Cell B1 on the Test (Destination) sheet.
The source data will look something like this:
Name 9/4/17 9/5/17 9/6/17 9/7/17
Bob 1 3 2 5
Shelly 2 1 7 3
Ralph 5 2 1 6
I need the macro to copy the value from the intersection of Bob and 9/5/17. I know this should be fairly easy, but my mind just isn't processing the problem correctly right now. Any suggestions would be greatly appreciated.
Thanks,
-Belzarak
I've been using a macro for quite some time to copy data based upon a single lookup value (Employee Name). This works great when the source data has fixed columns for the data needed. However, I'm now facing a challenge of needing to look up data not just based on the name, but also on the date that the event happened.
Here is the code I have been using:
Code:
Sub ClosedTest()
Dim wsSorc As Worksheet, wsDest As Worksheet
Dim cell As Range, Found As Range, counter As Long
'Define Source worksheet
Set wsSorc = Workbooks("Data.xlsx").Sheets("ClosedPivot")
'Define Destination worksheet
Set wsDest = Workbooks("Test.xlsm").Sheets("Tuesday")
'Loop for each used cell in column a source
For Each cell In wsSorc.Range("a2", wsSorc.Range("a" & Rows.Count).End(xlUp))
If Not IsEmpty(cell) Then
'Find match for column A source within column A destination
Set Found = wsDest.Range("A:A").Find(What:=cell.Value, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Found Is Nothing Then 'If Match was found...
'Copy to destination column B (1) matched row from Column C (3) source row
Found.Offset(, 1).Value = cell.Offset(, 3).Value
counter = counter + 1
Else
'No match was found
End If
End If
Next cell
End Sub
What I need is a way to take this code, or something similar, and add in a second search to find the matching Date. The Date will be in Row 4 on the Data (Source) sheet, and will be in Cell B1 on the Test (Destination) sheet.
The source data will look something like this:
Name 9/4/17 9/5/17 9/6/17 9/7/17
Bob 1 3 2 5
Shelly 2 1 7 3
Ralph 5 2 1 6
I need the macro to copy the value from the intersection of Bob and 9/5/17. I know this should be fairly easy, but my mind just isn't processing the problem correctly right now. Any suggestions would be greatly appreciated.
Thanks,
-Belzarak