6
votes

I want to export data from a set of named ranges in workbook x to another set of ranges in workbook y. The names of the ranges to be exported from and to are spesified in a table "Table_Export". Problem is I do not want to spesify in what sheets these respective ranges are located, seeing that I do not know the actual sheet names. But since the ranges are global it should somehow be possible to reference them in vba without referencing the respective worksheet?

The relevant code can be found below where either of the two starred lines within the if statement are what I want to accomplish.

Dim x As Workbook, y As Workbook    
Set x = ThisWorkbook
Set y = Workbooks.Open(Range("Export_to").Value)

Dim export_control As ListObject    
Set export_control = x.Sheets("Control").ListObjects("Table_Export")

Dim lr As Excel.ListRow    
For Each lr In export_control.ListRows
    If lr.Range(1).Value <> 0 Then    
        *'y.Names(lr.Range(2).Value).RefersToRange.Value = x.Names(lr.Range(1).Value).RefersToRange.Value*    
        *'y.Range(lr(Range(2).Value).Value = x.Range(lr(Range(1).Value).Value*    
    End If
Next
1

1 Answers

10
votes

Use the Property Names of the respective Workbook objects to reference Global Names.