Copy data from several sheets to the master

sofas

Well-known Member
Joined
Sep 11, 2022
Messages
559
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Welcome. I'm trying to copy data from several specific sheets to the main one. But I'm having a problem copying data over each other. Can you please correct the error?

Is there a possibility to add another condition so that all sheets in row 9, starting from column U, are searched for the value of cell M2 Sheet2 and fetch the values corresponding to the search value R12?

VBA Code:
Sub EssaiFiltreArrayClé()
Dim f As Variant

Dim ws As Worksheet:  Set ws = Sheets("Sheet2")
 
  Clé = ws.[R12]

Dim wsArray As Variant: wsArray = Array("Sheet1", "Sheet2", "Sheet3")
 
For Each f In Worksheets(wsArray)
Tbl1 = f.Range("c10:t" & f.[c65000].End(xlUp).Row).Value
 
  For i = 1 To UBound(Tbl1)
    If Tbl1(i, 16) = Clé Then n = n + 1
  Next i
  j = 0
  Dim Tbl2(): ReDim Tbl2(1 To n, 1 To UBound(Tbl1, 2))
  For i = 1 To UBound(Tbl1)
    If Tbl1(i, 16) = Clé Then j = j + 1: For k = 1 To UBound(Tbl1, 2): Tbl2(j, k) = Tbl1(i, k): Next k
 
 
   Next i
   ws.[C14].Resize(UBound(Tbl2), UBound(Tbl2, 2)) = Tbl2
Next f
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Welcome. I'm trying to copy data from several specific sheets to the main one. But I'm having a problem copying data over each other. Can you please correct the error?

Is there a possibility to add another condition so that all sheets in row 9, starting from column U, are searched for the value of cell M2 Sheet2 and fetch the values corresponding to the search value R12?

VBA Code:
Sub EssaiFiltreArrayClé()
Dim f As Variant

Dim ws As Worksheet:  Set ws = Sheets("Sheet2")
 
  Clé = ws.[R12]

Dim wsArray As Variant: wsArray = Array("Sheet1", "Sheet2", "Sheet3")
 
For Each f In Worksheets(wsArray)
Tbl1 = f.Range("c10:t" & f.[c65000].End(xlUp).Row).Value
 
  For i = 1 To UBound(Tbl1)
    If Tbl1(i, 16) = Clé Then n = n + 1
  Next i
  j = 0
  Dim Tbl2(): ReDim Tbl2(1 To n, 1 To UBound(Tbl1, 2))
  For i = 1 To UBound(Tbl1)
    If Tbl1(i, 16) = Clé Then j = j + 1: For k = 1 To UBound(Tbl1, 2): Tbl2(j, k) = Tbl1(i, k): Next k
 
 
   Next i
   ws.[C14].Resize(UBound(Tbl2), UBound(Tbl2, 2)) = Tbl2
Next f
End Sub
Hello, the second request does not matter if this is not possible. What I want now is to correct this code because it works well. The drawback is that it copies the data of the sheets on top of each other
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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