[VBA-E]Connaitre la lettre de la colonne en fonction du numero
Bonjour,
Q : COmment retrouver l'intitulé alphabétique d'une colonne en fonction de son numéro ?
R : Cette fonction le permet :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
Function LettreColonne(NumCol As Long) As String
Dim reste, quotient As Long
quotient = Int(NumCol / 26)
reste = NumCol Mod 26
If quotient = 0 And reste = 0 Then
Exit Function
End If
If quotient = 0 Then
LettreColonne = Chr(64 + reste)
Else
If reste = 0 Then
quotient = quotient - 1
If quotient = 0 Then
LettreColonne = Chr(64 + 26)
Else
LettreColonne = Chr(64 + quotient) & Chr(64 + 26)
End If
Else
LettreColonne = Chr(64 + quotient) & Chr(64 + reste)
End If
End If
End Function |
Cordialement. :)