Convert excel column alphabet (e.g. AA) to number (e.g., 25)

后端 未结 7 1803
余生分开走
余生分开走 2020-12-13 10:55

In my grid the column headers are named A,B,C...,AA,AB,AC,...etc like an excel spreadsheet. How can I convert the string to number like: A => 1, B =>

7条回答
  •  情话喂你
    2020-12-13 11:15

    Public Function ColLet2Num(Letras As String)
    'RALONSO MAYO 2017
    'A-> 1
    'OQ ->407
    'XFD->16384
    Dim UnChar As String
    Dim NAsc As Long
    Dim F As Long
    Dim Acum As Long
    Dim Indice As Long
    Letras = UCase(Letras)
    Acum = 0
    Indice = 0
    For F = Len(Letras) - 1 To 0 Step -1
    
        UnChar = Mid(Letras, F + 1, 1)
        NAsc = Asc(UnChar) - 64
        Acum = Acum + (NAsc * (26 ^ Indice))
        Indice = Indice + 1
    Next
    If Acum > 16384 Then
        MsgBox "La celda máxima es la XFD->16384", vbCritical
    End If
    ColLet2Num = Acum
    End Function
    

提交回复
热议问题