I've been trying to expand this macro which works for the first 3 sheets to a total of 6 sheets, but no matter what I try the macro seems to fail. Is there a problem with the way I'm doing it ?
Here's the original macro
Public Sub copyData()
Dim arrConfig(1, 2) As String
'Target sheetname | Source filename
arrConfig(0, 0) = "10k I": arrConfig(1, 0) = "1.xls"
arrConfig(0, 1) = "10k B": arrConfig(1, 1) = "2.xls"
arrConfig(0, 2) = "10k C": arrConfig(1, 2) = "3.xls"
'...
'arrconfig(0,6) = ...
Const pathDownloads As String = "/Users/bob/Downloads/"
Const AddressToCopy As String = "A1:M150"
Dim i As Long, wbSource As Workbook, wsSource As Worksheet, wsTarget As Worksheet
For i = 0 To UBound(arrConfig, 2)
Set wsTarget = ThisWorkbook.Worksheets(arrConfig(0, i))
wsTarget.Cells.Clear
Set wbSource = Workbooks.Open(pathDownloads & arrConfig(1, i))
Set wsSource = wbSource.Worksheets(1)
'This is the part where the data are written from one range to another (values only without formatting)
wsTarget.Range(AddressToCopy).Value = wsSource.Range(AddressToCopy).Value
wbSource.Close savechanges:=True
Next
End Sub
And here's the macro I tried to modify for a total of 6 sheets which does not work.
Public Sub copyData()
Dim arrConfig(1, 2) As String
'Target sheetname | Source filename
arrConfig(0, 0) = "10k I": arrConfig(1, 0) = "1.xls"
arrConfig(0, 1) = "10k B": arrConfig(1, 1) = "2.xls"
arrConfig(0, 2) = "10k C": arrConfig(1, 2) = "3.xls"
arrConfig(0, 0) = "10Q I": arrConfig(1, 0) = "4.xls"
arrConfig(0, 1) = "10Q B": arrConfig(1, 1) = "5.xls"
arrConfig(0, 2) = "10Q C": arrConfig(1, 2) = "6.xls"
'...
Const pathDownloads As String = "/Users/bob/Downloads/"
Const AddressToCopy As String = "A1:M150"
Dim i As Long, wbSource As Workbook, wsSource As Worksheet, wsTarget As Worksheet
For i = 0 To UBound(arrConfig, 2)
Set wsTarget = ThisWorkbook.Worksheets(arrConfig(0, i))
wsTarget.Cells.Clear
Set wbSource = Workbooks.Open(pathDownloads & arrConfig(1, i))
Set wsSource = wbSource.Worksheets(1)
'This is the part where the data are written from one range to another (values only without formatting)
wsTarget.Range(AddressToCopy).Value = wsSource.Range(AddressToCopy).Value
wbSource.Close savechanges:=True
Next
End Sub