Wheelie686
New Member
- Joined
- Oct 27, 2012
- Messages
- 11
The following code works fine to match a date on Sheet2 with the date in Sheet1!A1 and paste accordingly. However I tried to modify it so the paste destination is on another workbook but nothing seems to happen.
Does anybody know what I've done wrong in Test2
VBA Code:
Sub test()
Dim x
x = [match(Sheet1!A1,Sheet2!1:1,0)]
If IsNumeric(x) Then Sheets("Sheet2").Cells(6, x).Resize(4).Value = Sheets("Sheet1").[A2:A5].Value
End Sub
Code:
Sub test2()
Dim x
Dim Calc As Workbook
Dim Why As Workbook
Set Calc = ThisWorkbook
Set Why = Workbooks("Book2")
x = [match(Calc.Sheet1!A1,Why.Sheet2!1:1,0)]
If IsNumeric(x) Then Why.Sheets("Sheet2").Cells(6, x).Resize(4).Value = Calc.Sheets("Sheet1").[A2:A5].Value
End Sub
Does anybody know what I've done wrong in Test2