1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| Sub test_ReDimPreserve_Transpose()
tabl = ThisWorkbook.Sheets(1).Range("A1").CurrentRegion.Value
ReDim t(LBound(tabl, 2) To UBound(tabl, 2), LBound(tabl, 1) To 1)
ligne = LBound(tabl, 1)
For i = LBound(tabl, 1) To UBound(tabl, 1)
If Val(tabl(i, 2)) = 0 Then
' ne pas ajouter tabl(i)
Else
' ajouter tabl(i)
ReDim Preserve t(LBound(tabl, 2) To UBound(tabl, 2), LBound(tabl, 1) To ligne)
For J = LBound(tabl, 2) To UBound(tabl, 2)
t(J, ligne) = tabl(i, J)
Next
ligne = ligne + 1
End If
Next i
Set dest = ThisWorkbook.Worksheets(1).Range("E7").Resize(UBound(tabl, 1), UBound(tabl, 2))
dest.NumberFormat = "General"
dest.Value = tabl
Set dest = ThisWorkbook.Worksheets(1).Range("J7").Resize(ligne - 1, UBound(tabl, 2))
dest.NumberFormat = "General"
dest.Value = Application.WorksheetFunction.Transpose(t)
dest.Select
End Sub |
Partager