Vendredi 29 janvier 2010
5
29
/01
/Jan
/2010
16:18
Sub LONGUEUR_MAX_UNE_COLONNE()
'
'
'
Dim WS As Worksheet
Dim i As Integer
Dim com As String
Dim col As String
' parcours tous les cellules d'une colonne et retourne la taille maximale trouvée, :
col = InputBox("Entrez le nom de la colonne (A,B,...)", "Colonne", "A")
i = 0
For n = 1 To Rows.Count
If i < Len(Cells(n, col).Value) Then i = Len(Cells(n, col).Value)
Next n
MsgBox ("longueur maxi de " & col & " : " & i)
End Sub
Sub LONGUEUR_MAX_TOUTES_COLONNES()
'
'
'
Dim WS As Worksheet
Dim i As Integer
Dim com As String
Dim col As String
' parcours toutes les cellules de toutes les colonnes
' et retourne la taille maximale trouvée
' on ne tient pas compte de la première ligne qui contient les titres
com = " longueur maxi de "
For m = 1 To ActiveSheet.UsedRange.Columns.Count
i = 0
For n = 2 To ActiveSheet.UsedRange.Rows.Count
If i < Len(Cells(n, m).Value) Then i = Len(Cells(n, m).Value)
Next n
com = com & " " & Chr(64 + m) & " : " & i & " - "
Next m
MsgBox (com)
End Sub