copy data between 2 partially matched worksheets(in different workbooks) in vba

Viewed 20

i have 2 workbooks 1.remediation.xlsm 2.int_calculation.xlsx

on both workbooks some new worksheets are created dynamically when everytime I run a macro.

here I have added one new worksheet "123456" on remediation.xlsm file and another one called "Corrected_Accruals-123456" on int_calculation.xlsx file.

i need a piece of code which will take values from a range and search that in both workbooks , if there is a match it will copy data from 123456 and paste it on Corrected_Accruals-123456.

attaching my code for this one, I'm getting error-6 "overflow when running this on.

drive link for 2 workbooks

Sub Copy_Data()

Dim lastRow As Long

Dim offsetRow As Long

Dim i As Range

Dim opsheet As Worksheet

Dim inputsheet As Worksheet

Dim ip As Worksheet

Set inputsheet = Workbooks("remediation.xlsm").Worksheets("reference")
inputsheet.Activate
lastRow = inputsheet.Columns("A").Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row


For Each i In inputsheet.Range("A2: A" & lastRow)

Set opsheet = Workbooks("int_Calculation.xlsx").Worksheets("Corrected Accruals" & "-" & i.Value)

Set ip = Workbooks("remediation.xlsm").Worksheets(i.Value)



opsheet.Cells("A5") = ip.Cells("A5")
opsheet.Cells("B5") = ip.Cells("B5")
opsheet.Cells("D5") = ip.Cells("D5")
opsheet.Cells("E5") = ip.Cells("E5")

Next i

End Sub
0 Answers
Related