Link to home
Start Free TrialLog in
Avatar of VBdotnet2005
VBdotnet2005Flag for United States of America

asked on

get letter from "AX"

I am trying to read from Excel file starting from column "AX" up to column "CU".  This is on the header only.
My logic is not working right.        
   
Dim j As Integer = 0

        For j = 1 To 50
            Dim firstalpha As Integer = j / 26
            Dim secondalpha As Integer = (j - 1) Mod 26
            Dim letter As String = Convert.ToChar(65 + secondalpha)
            If firstalpha > 0 Then
                letter = Convert.ToChar(64 + firstalpha) + letter
            End If

        Next
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Éric Moreau
I have this very old code that used to work:

'    Public Shared Function NextNomColumn(ByVal pstrCol As String) As String
'        If pstrCol Is Nothing Then
'            Throw New ArgumentNullException("pstrCol")
'        End If

'        Dim strFirst As String
'        Dim strLast As String

'        If pstrCol.Length = 1 Then
'            strFirst = ""
'            strLast = pstrCol
'        Else
'            strFirst = pstrCol.Substring(0, 1)
'            strLast = pstrCol.Substring(1, 1)
'        End If

'        If strLast = "Z" Then
'            If strFirst = "" Then
'                strFirst = "A"
'            Else
'                'strFirst = Chr$(Asc(strFirst) + 1)
'                strFirst = Convert.ToChar(Convert.ToInt32(Convert.ToChar(strFirst)) + 1)
'            End If
'            strLast = "A"
'        Else
'            'strLast = Chr$(Asc(strLast) + 1)
'            strLast = Convert.ToChar(Convert.ToInt32(Convert.ToChar(strLast)) + 1)
'        End If

'        NextNomColumn = strFirst & strLast
'    End Function
Avatar of VBdotnet2005

ASKER

PaulHews
That works for me. Thank you