- Option Explicit
-
- Private Function GetColonnes(ByVal s As String, ByVal n As Integer) As String
- Dim i As Integer
- Dim j As Integer
- Dim c As String
-
- ' il y a 26 lettres dans l'alphabet, donc si on dépasse ce chiffre c'est qu'il faut plusieurs lettres
- If n > 26 Then
- i = Int(n / 26)
- If (n Mod 26) <> 0 Then
- j = n Mod 26
- Else
- j = 26: i = i - 1
- End If
- ' on appelle une nouvelle fois la fonction
- GetColonnes = s + GetColonnes(Chr(64 + i), j) ' 64 correspond au caractère '@' (juste avant 'A')
- Else
- c = Chr(64 + n)
- GetColonnes = s + c
- End If
- End Function
-
- Public Function getCell(ByVal X As Integer, ByVal Y As Integer) As String
- getCell = GetColonnes("", X) & CStr(Y)
- End Function
-
- Private Sub Form_Load()
- ' Quelques exemples :
- MsgBox getCell(10, 10) ' donne J10
- MsgBox getCell(48, 55) ' donne AV55
- End
- End Sub
Option Explicit
Private Function GetColonnes(ByVal s As String, ByVal n As Integer) As String
Dim i As Integer
Dim j As Integer
Dim c As String
' il y a 26 lettres dans l'alphabet, donc si on dépasse ce chiffre c'est qu'il faut plusieurs lettres
If n > 26 Then
i = Int(n / 26)
If (n Mod 26) <> 0 Then
j = n Mod 26
Else
j = 26: i = i - 1
End If
' on appelle une nouvelle fois la fonction
GetColonnes = s + GetColonnes(Chr(64 + i), j) ' 64 correspond au caractère '@' (juste avant 'A')
Else
c = Chr(64 + n)
GetColonnes = s + c
End If
End Function
Public Function getCell(ByVal X As Integer, ByVal Y As Integer) As String
getCell = GetColonnes("", X) & CStr(Y)
End Function
Private Sub Form_Load()
' Quelques exemples :
MsgBox getCell(10, 10) ' donne J10
MsgBox getCell(48, 55) ' donne AV55
End
End Sub