I am going to import some values from one workbook to another.
I want to do this by looping through the named ranges in the target workbook, and copy those named ranges in source workbook with exact similar name. The relevant names to be copied are listed in a worksheet called "Names" in the target workbook.
The actual named ranges are located in a worksheet called TargetSheet (I have given many single cells one name).
I know how to copy one named range from a workbook to another, when typing this, it works:
ThisWorkbook.Sheets("TargetSheet").Range("TagName") = _ Workbooks("Source").Sheets("SourceSheet").Range("TagName").
However, I don't manage to make a loop that copies values from all relevant named ranges, even if I include quotation marks in the string.
For i = 2 To 8
For j = 1 To 6
CurrentName = """" & ThisWorkbook.Sheets("Names").Cells(i, j) & """"
ThisWorkbook.Sheets("Target").Range(CurrentName) = _
Workbooks("Source").Sheets("SourceSheet").Range(CurrentName)
Next j
Next i
The code above gives error message 'Application defined or object defined error', while I hoped that some 42 cells would get updated values.