Private Function GetColumnName(ByVal colNumber As Integer) As String
Dim colName As String = String.Empty
Dim quotient As Integer = 0
Dim remainder As Integer = 0
If colNumber <= 26 Then
colName = Convert.ToChar(colNumber + 64)
Return colName
Else
Dim fChar As String = String.Empty
Dim sChar As String = String.Empty
quotient = colNumber \ 26
remainder = colNumber Mod 26
If remainder = 0 Then
fChar = Me.GetColumnName(quotient - 1)
Else
fChar = Me.GetColumnName(quotient)
End If
If remainder = 0 Then
sChar = "Z"
Else
sChar = Me.GetColumnName(remainder)
End If
Private Function GetColumnName(ByVal colNumber As Integer) As String
That can be greatly simplified to:
Function ColLetter(ColNum As Long) As String
ColLetter = Split(Worksheets(1).Cells(1, ColNum).Address(True, False),
"$")(0)
End Function
--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting www.cpearson.com
(email on the web site)
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.