Skip to content

Instantly share code, notes, and snippets.

@dck-jp
Created December 3, 2014 01:06
Show Gist options
  • Select an option

  • Save dck-jp/3289715126246ff0265d to your computer and use it in GitHub Desktop.

Select an option

Save dck-jp/3289715126246ff0265d to your computer and use it in GitHub Desktop.
Excelの列番号<->列名 変換
'-------------------------------------------------------------------------
' 列番号<->列名 変換
'-------------------------------------------------------------------------
'英文字を列番号値に変換
''' @param strCol As String 変換する列文字列
Public Function L2N(strCol As String)
L2N = Range(strCol & 1).column
End Function
'列番号値を同等の英文字に変換
''' @param iCol As Integer 変換する列番号
Function N2L(iCol As Integer) As String
Dim iAlpha As Integer
Dim iRemainder As Integer
iAlpha = Int((iCol - 1) / 26)
iRemainder = iCol - (iAlpha * 26)
If iAlpha > 0 Then
N2L = Chr(iAlpha + 64)
End If
If iRemainder > 0 Then
N2L = N2L & Chr(iRemainder + 64)
End If
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment