Sub Resultat()
Dim nlig&, ncol%, tablo, resu1(), resu2(), resu3(), resu4(), n%, nmax%
nlig = 5 'à adapter
With [A1].CurrentRegion
ncol = .Columns.Count
If ncol = 1 Then ncol = 2
tablo = .Resize(nlig, ncol) 'matrice, plus rapide, au moins 2 éléments
End With
Remplir nlig, ncol, tablo, 2, resu1, n: nmax = n
Remplir nlig, ncol, tablo, 3, resu2, n: If n > nmax Then nmax = n
Remplir nlig, ncol, tablo, 4, resu3, n: If n > nmax Then nmax = n
Remplir nlig, ncol, tablo, 5, resu4, n: If n > nmax Then nmax = n
MsgBox "Nombre maximum de colonnes : " & nmax, , "Résultat"
End Sub
Sub Remplir(nlig&, ncol%, tablo, i&, resu(), nmax%)
Dim j%, n%
nmax = 0
For j = 2 To ncol
If tablo(i, j) <> "" Then
n = n + 1
ReDim Preserve resu(1 To n) 'tableau a une dimension (vecteur horizontal)
resu(n) = tablo(i, j)
End If
Next
'---restitution---
With Cells(i + nlig + 1, 2) 'à adapter
If n Then .Resize(, n) = resu: nmax = n
.Offset(, n).Resize(, Columns.Count - n - .Column + 1).ClearContents 'RAZ à droite
End With
End Sub