-1

I'm am using the code example below to represent an integer as an alphabetic string

Private Function GetExcelColumnName(columnNumber As Integer) As String
Dim dividend As Integer = columnNumber
Dim columnName As String = String.Empty
Dim modulo As Integer

While dividend > 0
   modulo = (dividend - 1) Mod 26
   columnName = Convert.ToChar(65 + modulo).ToString() & columnName
   dividend = CInt((dividend - modulo) / 26)
End While
Return columnName
End Function

I found the above example here: Converting Numbers to Excel Letter Column vb.net

How do I get the reverse, for example:

123 = DS -- Reverse -- DS = 123

35623789 = BYXUWS -- Reverse -- BYXUWS = 35623789

Is it possible to get the number from the alphabetic string without importing Excel?

Craig
  • 79
  • 9
  • 1
    Of course it is possible. Study the code you have so that you understand what it is doing and then write code that does the reverse. If you have problems with that code, post it and ask for help in correcting it. – Blackwood Feb 18 '18 at 15:12
  • @Blackwood, I have been studying the code for two hours. If I knew how to reverse it I would not have asked the question here. Do you perhaps know what the reverse function would be? – Craig Feb 18 '18 at 15:18

1 Answers1

2

I found an answer from another post. This function below will work to get the reverse

Public Function GetCol(c As String) As Long
Dim i As Long, t As Long
c = UCase(c)
For i = Len(c) To 1 Step -1
    t = t + ((Asc(Mid(c, i, 1)) - 64) * (26 ^ (Len(c) - i)))
Next i
GetCol = t
End Function
Craig
  • 79
  • 9