Hi
I'm trying to copy specific data from one workbook to another workbook. I'm using the following code and getting error message "Subscription out of range" - please can someone help me with this.
I'm trying to copy specific data from one workbook to another workbook. I'm using the following code and getting error message "Subscription out of range" - please can someone help me with this.
VBA Code:
Option Explicit
Option Base 1
Sub CopyTo()
Dim Cel As Range
Dim wsc As Worksheet, wst As Worksheet
Dim wbc As Workbook, wbt As Workbook
Dim arrc, arrt
Dim k&, i&, j&, m&
Dim mydata As Workbook
Set wbc = ThisWorkbook
Set wsc = wbc.Worksheets("sheet1")
arrc = wsc.[A85:D93]
k = 1: m = 0
ReDim arrt(1, UBound(arrc, 1) * (UBound(arrc, 2) - 1))
For i = 1 To UBound(arrc, 1)
For j = 2 To UBound(arrc, 2)
arrt(k, m + j - 1) = arrc(i, j)
Next j
m = m + 5
Next i
Set mydata = Workbooks.Open("C:\Users\mybook.xlsx")
Set wbt = Workbooks("mybook.xlsx")
Set wst = wbt.Worksheets("Data")
i = WorksheetFunction.Match(UCase(wsc.[t3]), wst.[a5:a82], 0)
wst.Cells(i, 2).Resize(UBound(arrt, 1), UBound(arrt, 2)) = arrt
mydata.Save
mydata.Close
End Sub