Please see the complete code below. I have two questions:
1. What does the bold part do?
Ex. Resize(UBound(x, 1), UBound(x, 2))
2. Why = x?
Ex. CurrWkbk.Worksheets("Data").Range("C8").Offset(0, (3 * i - 3)).Resize(UBound(x, 1), UBound(x, 2)) = x
Thanks!
Sub CopyPasteXY()
Application.ScreenUpdating = False
Dim WkbkName As String
Dim RemoteWkbk As Excel.Workbook, CurrWkbk As Excel.Workbook
Dim i As Long
Set CurrWkbk = ActiveWorkbook
i = 1
While Len(Range("FileList").Offset(i, 0)) > 0
WkbkName = Range("FileList").Offset(i, 0)
'Open workbook
Set RemoteWkbk = Workbooks.Open(WkbkName)
' Copy contents
x = RemoteWkbk.Worksheets("General Information").Range("B9:B12").Value
y = RemoteWkbk.Worksheets("Section 1)").Range("B8:D20").Value
' Paste contents
CurrWkbk.Worksheets("Data").Range("C8").Offset(0, (3 * i - 3)).Resize(UBound(x, 1), UBound(x, 2)) = x
CurrWkbk.Worksheets("Data").Range("C13").Offset(0, (3 * i - 3)).Resize(UBound(y, 1), UBound(y, 2)) = y
RemoteWkbk.Close False
i = i + 1
Wend
Application.ScreenUpdating = False
End Sub
1. What does the bold part do?
Ex. Resize(UBound(x, 1), UBound(x, 2))
2. Why = x?
Ex. CurrWkbk.Worksheets("Data").Range("C8").Offset(0, (3 * i - 3)).Resize(UBound(x, 1), UBound(x, 2)) = x
Thanks!
Sub CopyPasteXY()
Application.ScreenUpdating = False
Dim WkbkName As String
Dim RemoteWkbk As Excel.Workbook, CurrWkbk As Excel.Workbook
Dim i As Long
Set CurrWkbk = ActiveWorkbook
i = 1
While Len(Range("FileList").Offset(i, 0)) > 0
WkbkName = Range("FileList").Offset(i, 0)
'Open workbook
Set RemoteWkbk = Workbooks.Open(WkbkName)
' Copy contents
x = RemoteWkbk.Worksheets("General Information").Range("B9:B12").Value
y = RemoteWkbk.Worksheets("Section 1)").Range("B8:D20").Value
' Paste contents
CurrWkbk.Worksheets("Data").Range("C8").Offset(0, (3 * i - 3)).Resize(UBound(x, 1), UBound(x, 2)) = x
CurrWkbk.Worksheets("Data").Range("C13").Offset(0, (3 * i - 3)).Resize(UBound(y, 1), UBound(y, 2)) = y
RemoteWkbk.Close False
i = i + 1
Wend
Application.ScreenUpdating = False
End Sub