The following code works when I execute it from the WB workbook but returns error 1004 when I run it from WBi workbook I need to run it from WBi Woorkbook. Thx for the help in advance
Code:
Option Explicit
Sub MatchCopy()
Dim WB As Workbook
Dim WBi As Workbook
Dim FindString1 As Long
Dim FindString2 As Long
Dim Lcol1 As Long
Dim Lcol2 As Long
Dim Lrow1 As Long
Dim Lrow2 As Long
Application.ScreenUpdating = False
Set WBi = Workbooks("WBi.xlsm")
Set WB = Workbooks("WB.xlsx")
WBi.Sheets("Sheet1").Range("A1:B180").Clear
FindString1 = "104"
FindString2 = "301"
With WB.Sheets("Sheet1")
Lcol1 = Application.Match(FindString1, .Rows(27), 0)
Lcol2 = Application.Match(FindString2, .Rows(6), 0)
Lrow1 = Cells(Rows.count, Lcol1).End(xlUp).Row
Lrow2 = Cells(Rows.count, Lcol2).End(xlUp).Row
.Range(Cells(27, Lcol1), Cells(Lrow1, Lcol1)).Copy WBi.Sheets("Sheet1").Range("A1")
.Range(Cells(6, Lcol2), Cells(Lrow2, Lcol2)).Copy WBi.Sheets("Sheet1").Range("B1")
End With
Application.ScreenUpdating = True
End Sub