Function to convert column number to letter?

后端 未结 28 1988
灰色年华
灰色年华 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条回答
  •  清歌不尽
    2020-11-22 07:55

    Just one more way to do this. Brettdj's answer made me think of this, but if you use this method you don't have to use a variant array, you can go directly to a string.

    ColLtr = Cells(1, ColNum).Address(True, False)
    ColLtr = Replace(ColLtr, "$1", "")
    

    or can make it a little more compact with this

    ColLtr = Replace(Cells(1, ColNum).Address(True, False), "$1", "")
    

    Notice this does depend on you referencing row 1 in the cells object.

提交回复
热议问题