Convert column number to the column letter for message box

Dallie

New Member
Joined
Apr 12, 2018
Messages
13
Hi,

I have message box that I am trying to convert from a column number to column letter to make the code more user friendly as I was performing this on Column AC which is column 29 (much more confusing)

How would I go about converting the column number to column letter for this code?

Code:
c = Selection.column
If MsgBox("Check column " & c & "?", vbOKCancel) = vbOK Then

Thanks!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Code:
Function ColLtr(ByVal iCol As Long) As String
  ' shg 2012
  ' Good for any positive Long
  If iCol > 0 Then ColLtr = ColLtr((iCol - 1) \ 26) & Chr(65 + (iCol - 1) Mod 26)
End Function

E.g.

Code:
If MsgBox("Check column " & ColLtr(c) & "?", vbOKCancel) = vbOK Then
 
Upvote 0
Here is one way:
Code:
Dim addr As String
Dim c As String

addr = Selection.Address(0, 0)
c = Left(addr, Len(addr) - Len(Selection.Row))
MsgBox "Check column " & c
 
Upvote 0
Here's a UDF - Paste into a Standard Module.

Select a Cell in your worksheet, say M1; then run the macro Foo...

Code:
Sub Foo()
c = ColLetter(Selection.Column)
MsgBox "Check column " & c & "?"
End Sub


Function ColLetter(ColNumber As Integer) As String
    ColLetter = Left(Cells(1, ColNumber).Address(False, False), _
        1 - (ColNumber > 26))
End Function
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,007
Members
448,935
Latest member
ijat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top