July 30, 2011

Translate an Excel column number to its equivalent column letter using Visual Basic .NET

Private Function GetColumnLetter(ByVal columnNumber As Integer) As String
    Dim columnLetter As String
    If columnNumber <= 25 Then
        columnLetter = Chr(65 + columnNumber)
    Else
        columnLetter = GetColumnLetter(columnNumber \ 26 - 1)
        columnLetter &= Chr(65 + columnNumber Mod 26)
    End If
    Return columnLetter
End Function