Récupérer le numéro de colonne

Bonjour le forum,

j'ai plusieurs colonnes, chaque colonne à plus ou moins de lignes.

Je voudrais récupérer le numéro de colonne qui possède le plus de ligne, auriez vous une idée?

Merci.

Salut Benoist,

une façon de faire, à coller dans le module de la feuille concernée.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'
iCol = Cells(1, Columns.Count).End(xlToLeft).Column
For x = 1 To iCol
    iRow = Cells(Rows.Count, x).End(xlUp).Row
    sCol = Split(Columns(x).Address(ColumnAbsolute:=False), ":")(1)
    Select Case iRow
        Case Is > iPlus
            iPlus = iRow
            sMsg = sCol
        Case Is = iPlus
            sMsg = sMsg & " " & sCol
    End Select
Next
MsgBox "Colonne(s) comptant le plus de lignes: " & sMsg, vbInformation
'
End Sub

A+

Un grand merci curulis57, je l'ai réadapter à mon code et ça marche parfaitement.

Si ça peut aider quelqu'un:

Private O As Worksheet 'déclare la variable O (Onglet)

Sub Rectangle1_Cliquer()
Dim DerLigne As Integer
Dim DerColonne As Integer
Dim NumColonne As Integer

If Sheets("Accueil").Range("D5").Value = 0 Then
Set O = Worksheets("Dépenses") 'définit l'onglet O
Else: Sheets("Accueil").Range("D5").Value = 1
Set O = Worksheets("Revenus") 'définit l'onglet O
End If

DerColonne = O.Cells(1, Cells.Columns.Count).End(xlToLeft).Column
Application.ScreenUpdating = False

For NumColonne = 1 To DerColonne
DerLigne = O.Cells(Cells.Rows.Count, NumColonne).End(xlUp).Row
O.Select
O.Range(Cells(2, NumColonne), Cells(DerLigne, NumColonne)).Select
O.Sort.SortFields.Clear
O.Sort.SortFields.Add Key:=Cells(2, NumColonne), _
         SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With O.Sort
        .SetRange Range(Cells(2, NumColonne), Cells(DerLigne, NumColonne))
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
Next NumColonne

iCol = Cells(1, Columns.Count).End(xlToLeft).Column
For x = 1 To iCol
    iRow = Cells(Rows.Count, x).End(xlUp).Row
    sCol = Split(Columns(x).Address(ColumnAbsolute:=False), ":")(1)
    Select Case iRow
        Case Is > iPlus
            iPlus = iRow
            sMsg = sCol
        Case Is = iPlus
            sMsg = sMsg & " " & sCol
    End Select
Next

Range(Cells(1, 1), Cells(iPlus, DerColonne)).Select
    O.Sort.SortFields.Clear
    O.Sort.SortFields.Add Key:=Range(Cells(1, 1), Cells(1, DerColonne)) _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With O.Sort
        .SetRange Range(Cells(1, 1), Cells(iPlus, DerColonne))
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlLeftToRight
        .SortMethod = xlPinYin
        .Apply
    End With

Application.ScreenUpdating = True
End Sub
Rechercher des sujets similaires à "recuperer numero colonne"