Match data to find intersection
This is the code I've done to accomplish this. I actually tried it out using
two sheets in the same workbook and got it working perfectly. Now that I've
moved it to two seperate workbooks I'm getting an error that I'm sure has to
do with the way I'm calling a workbook as a variable. Any advice?
Private Sub butWeeklyLabor_Click()
Dim WLH As Variant
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim dat As Range
Dim col As Long
Dim num As Range
Dim rw As Long
Dim hours As Range
Dim cell As Range
Dim Lr3 As Long
Dim IntR As Long
Dim Lr4 As Long
Dim wb As Workbook
ChDir "C:\DOCUMENTS AND SETTINGS\sbauer\Desktop\Burney"
WLH = Application.GetOpenFilename()
If WLH = False Then
End
Else
Set wb = Workbooks.Open(WLH)
End If
Set ws1 = ThisWorkbook.Worksheets("Sheet1")
Set ws2 = Workbooks(wb).Worksheets("Sheet1")
Lr3 = LastRow(ws1)
Lr4 = LastRow(ws2) - 2
For i = 8 To Lr3
Set dat = ws1.Cells(i, 1)
Set num = ws1.Cells(i, 2)
'Find column that matches date
col = ws2.Rows(4).Find(dat).Column
'Find row that matches employee number
rw = ws2.Columns(1).Find(num).Row
Set hours = ws1.Cells(i, 6)
'Put hours in intersection cell
ws2.Range("A1:I" & Lr4).Cells(rw, col).Value = hours
Next
End Sub
|