I have searched for such a topic and found a UDF that combines 2d arrays into one array. I tried to loop through the worksheets like that and store the data in alll worksheets except "Search" worksheet
Sub Test()
Dim a, temp, ws As Worksheet, m As Long
Application.ScreenUpdating = False
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Search" Then
m = ws.Cells(Rows.Count, 1).End(xlUp).Row
temp = ws.Range("A4:L" & m).Value
On Error Resume Next
'If UBound(a) > 0 Then GoTo nextP
If a = Empty Then a = temp
On Error GoTo 0
nextP:
a = Combine(a, temp)
End If
Next ws
Stop
Application.ScreenUpdating = True
'a = Range("A1:C2").Value
'b = Range("A4:C5").Value
'Range("F1").Resize(UBound(a, 1) * 2, UBound(a, 2)).Value = Combine(a, b)
'Range("J1").Resize(UBound(a, 1), UBound(a, 2) * 2).Value = Combine(a, b, False)
End Sub
Function Combine(a, b, Optional f As Boolean = True)
Dim c, lb As Long, m_A As Long, n_A As Long, m_B As Long, n_B As Long, m As Long, n As Long, i As Long, j As Long
If TypeName(a) = "Range" Then a = a.Value
If TypeName(b) = "Range" Then b = b.Value
lb = LBound(a, 1)
m_A = UBound(a, 1)
n_A = UBound(a, 2)
m_B = UBound(b, 1)
n_B = UBound(b, 2)
If f Then
m = m_A + m_B + 1 - lb
n = n_A
If n_B <> n Then Combine = False: Exit Function
Else
m = m_A
If m_B <> m Then Combine = False: Exit Function
n = n_A + n_B + 1 - lb
End If
ReDim c(lb To m, lb To n)
For i = lb To m
For j = lb To n
If f Then
If i <= m_A Then
c(i, j) = a(i, j)
Else
c(i, j) = b(lb + i - m_A - 1, j)
End If
Else
If j <= n_A Then
c(i, j) = a(i, j)
Else
c(i, j) = b(i, lb + j - n_A - 1)
End If
End If
Next j
Next i
Combine = c
End Function
The code works and I got one array but the number of rows are duplicates .. Example: if the number of rows in all worksheets are 20 rows, I got an array of 40 rows .. Any idea how to fix that? Simply my request is about how to append 2d array to th main array??