Copy values between ranges with the same name in different workbooks

Olbap

New Member
Joined
Nov 6, 2009
Messages
19
Hi,

I am trying to copy just the values from one range in one file to another file with the same range name, I wonder if this is at the origin of the "subscript out of range" error message I get.

Here is the code, where it stucks is in red:


Sub UpdateToFinalFile()
Dim ws As Worksheet
Dim cl As Range
Dim finalfile As String
Dim thisWB As String
Dim clad As String

finalfile = Range("finalfile").value
thisWB = ActiveWorkbook.Name
Workbooks.Open Filename:=finalfile
Workbooks(thisWB).Activate
For Each ws In Worksheets
If Left(ws.Name, 2) = "T_" Then

For Each cl In Workbooks(thisWB).Worksheets(ws.Name).Range("Data").Cells
clad = cl.Address
If cl.value <> "" And cl.value <> Workbooks(finalfile).Worksheets(ws.Name).Cells(cl.Row, cl.Column).value Then
Workbooks(finalfile).Worksheets(ws.Name).Range(clad).value = cl.value
End If
Next cl
Workbooks(thisWB).Worksheets("Contents").Cells(30, 1).value = ws.Name & " OK"
End If
Next ws
End Sub


Each range "Data" is specific to each sheet and my files are located in different drives.
P
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Olbap:

Need to clear the path of finalfile
Try below code

Code:
If cl.value <> "" And cl.value <> Workbooks(Dir(finalfile)).Worksheets(ws.Name).Cells(cl.Row, cl.Column).value Then
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top