Function to convert column number to letter?

后端 未结 28 1576
灰色年华
灰色年华 2020-11-22 07:04

Does anyone have an Excel VBA function which can return the column letter(s) from a number?

For example, entering 100 should return CV.

28条回答
  •  -上瘾入骨i
    2020-11-22 07:34

    There is a very simple way using Excel power: Use Range.Cells.Address property, this way:

    strCol = Cells(1, lngRow).Address(xlRowRelative, xlColRelative)
    

    This will return the address of the desired column on row 1. Take it of the 1:

    strCol = Left(strCol, len(strCol) - 1)
    

    Note that it so fast and powerful that you can return column addresses that even exists!

    Substitute lngRow for the desired column number using Selection.Column property!

提交回复
热议问题