Hello. I am trying to copy data from several specific sheets to the main one using the following code, but I am facing a problem that it copies the data and empties it at the same time. I do not know what to do.
VBA Code:
Sub EssaiFiltreArrayClé()
Dim f As Variant
Dim ws As Worksheet: Set ws = Sheets("sh")
Clé = ws.[a2]
Dim wsArray As Variant: wsArray = Array("Sheet1", "Sheet2", "Sheet4")
For Each f In Worksheets(wsArray)
Rng = f.Range("A2:G" & f.[A65000].End(xlUp).Row).Value
For i = 1 To UBound(Rng)
If Rng(i, 1) = Clé Then n = n + 1
Next i
j = 0
Dim Tbl(): ReDim Tbl(1 To n, 1 To UBound(Rng, 2))
For i = 1 To UBound(Rng)
If Rng(i, 1) = Clé Then
j = j + 1
For k = 1 To UBound(Rng, 2): Tbl(j, k) = Rng(i, k)
Next k
End If
Next i
ws.[d14].Resize(UBound(Tbl), UBound(Tbl, 2)) = Tbl
Next f
End Sub