Function to convert column number to letter?

后端 未结 28 2012
灰色年华
灰色年华 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:50

    The solution from brettdj works fantastically, but if you are coming across this as a potential solution for the same reason I was, I thought that I would offer my alternative solution.

    The problem I was having was scrolling to a specific column based on the output of a MATCH() function. Instead of converting the column number to its column letter parallel, I chose to temporarily toggle the reference style from A1 to R1C1. This way I could just scroll to the column number without having to muck with a VBA function. To easily toggle between the two reference styles, you can use this VBA code:

    Sub toggle_reference_style()
    
    If Application.ReferenceStyle = xlR1C1 Then
      Application.ReferenceStyle = xlA1
    Else
      Application.ReferenceStyle = xlR1C1
    End If
    
    End Sub
    

提交回复
热议问题