Sub compilBDD()
Dim f As Worksheet
li = 1
With Sheets("BDD Tous")
.Cells.Clear
For Each f In Worksheets
If f.Name Like "BDD Soc*" Then
For i = 1 To f.Cells(2, Columns.Count).End(xlToLeft).Column Step 10
If f.Cells(2, i) <> "" Then
nblignes = f.Cells(2, i).CurrentRegion.Rows.Count
nbcolonnes = f.Cells(2, i).CurrentRegion.Columns.Count
f.Cells(2, i).CurrentRegion.Offset(1, 0).Resize(nblignes - 1, nbcolonnes).Copy
.Cells(li, 1).PasteSpecial Paste:=xlPasteValues
.Cells(li, 1).PasteSpecial Paste:=xlPasteFormats
li = .Cells(Rows.Count, 1).End(xlUp).Row + 1
End If
Next
End If
Next
MsgBox .Cells(1, 1).CurrentRegion.Rows.Count & " lignes recopiées."
donnee = .Cells(1, 1).CurrentRegion.Value
.Cells.Clear
donnee = epuration(donnee)
.Cells(1, 1).Resize(UBound(donnee), UBound(donnee, 2)) = donnee
MsgBox .Cells(1, 1).CurrentRegion.Rows.Count & " lignes valides."
End With
End Sub
Function epuration(Tbl)
Dim i%, ii%, j%, k%, n%, flag As Boolean
For i = 1 To UBound(Tbl)
flag = False
For j = 1 To UBound(Tbl, 2)
If Tbl(i, j) <> 0 Then flag = True
Next j
If flag Then n = n + 1
Next i
Dim temp: ReDim temp(1 To n, 1 To UBound(Tbl, 2))
j = 0
For i = 1 To UBound(Tbl)
flag = False
For j = 1 To UBound(Tbl, 2)
If Tbl(i, j) <> 0 Then flag = True
Next j
If flag Then
ii = ii + 1
For k = 1 To UBound(Tbl, 2)
temp(ii, k) = Tbl(i, k)
Next k
End If
Next i
epuration = temp
End Function