ActiveCell.Column returns # instead of a letter

starfish

New Member
Joined
Dec 15, 2002
Messages
2
I'm trying to use ActiveCell.Column to store a column letter in a variable to be used later.

Only trouble is that it is returning a number instead of a letter. So column C shows up as 3.

Is there a way to make the function return the letter?

I'm using this to store the column letter so that I can move to known rows within a variable column that need to be pasted to another sheet.

Thanks in advance for any help. :)
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
There is very little reason why one needs the letter corresponding to a column. In code, it is almost always easier to deal with a number, for example, Cells(row-number,column-number)
 
Upvote 0
Howdy, this is essentially the same as Dan's linked variety, but looks shorter...<pre>
Function GetCol(ByVal n As Range)
If n.Column< 27 Then GetCol = Chr(64 + n.Column) Else _
GetCol = Chr(64 + n.Column 26) + Chr(64 + (n.Column Mod 26))
End Function</pre>

This particular function takes a range, e.g.,

=getcol(iv4)

_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue"> Oliver</font></font></font>
This message was edited by nateo on 2002-12-16 20:32
 
Upvote 0
Ummm...not quite.

Modified version that works with cols ending in 'Z' (such as AZ, BZ, etc.):
<pre>Function GetCol(ByVal n As Range)
If n.Column <= 26 Then GetCol = Chr(64 + n.Column) Else _
GetCol = Chr(64 + (n.Column - 1) 26) + Chr(64 + 1 + ((n.Column - 1) Mod 26))
End Function
</pre>.
On 2002-12-16 20:24, NateO wrote:
Howdy, this is essentially the same as Dan's linked variety, but looks shorter...

<pre>
Function GetCol(ByVal n As Range)
If n.Column < 27 Then GetCol = Chr(64 + n.Column) Else _
GetCol = Chr(64 + n.Column 26) + Chr(64 + (n.Column Mod 26))
End Function</pre>

This particular function takes a range, e.g.,

=getcol(iv4)
{snip}
 
Upvote 0
That didn't work for me for columns over AZ
But this did

Function GetCol(ByVal n As Range)
If n.Column <= 26 Then GetCol = Chr(64 + n.Column) Else _
GetCol = Chr(64 + (n.Column - 1 - (n.Column - 1) Mod 26) / 26) + Chr(64 + 1 + ((n.Column - 1) Mod 26))
End Function
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,638
Messages
6,120,674
Members
448,977
Latest member
moonlight6

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