VBdotnet2005
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
PaulHews
That works for me. Thank you
That works for me. Thank you
' Public Shared Function NextNomColumn(ByVal pstrCol As String) As String
' If pstrCol Is Nothing Then
' Throw New ArgumentNullException("pst
' 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.ToI
' End If
' strLast = "A"
' Else
' 'strLast = Chr$(Asc(strLast) + 1)
' strLast = Convert.ToChar(Convert.ToI
' End If
' NextNomColumn = strFirst & strLast
' End Function