Error converting a column number to letters

insomniac53

Board Regular
Joined
Sep 3, 2013
Messages
104
I have been using this function for some time to convert a column number to letters. It should take any number and return the correct letters, even double letters, e.g. AH etc. It works, but there is at least one number which causes it to fail - that number is 36.
Here is the function:

Code:
Public Function ntc(ByVal iCol As Long) As String 'Number To String (returns ANY column LETTER)
    If iCol Then ntc = ntc((iCol - 1) \ 26) & Chr(65 + (iCol - 1) Mod 26)
End Function

When iCol is 35, function returns "AI" and when iCol is 37, function returns "AK" but when iCol is 36 function is undefined.
Can anyone see why it fails when iCol is 36 (and probably multiples of 36, too) ?

Thank you.
 
Two further comments:

Hmm... can't see how to mark this as Solved...
We don't have that 'feature' in this forum because quite often an even better solution comes along after the OP states that the question is solved and we don't want to discourage that. :)


IF a formula solution was being considered, the OP didn't ask for the letters in the column itself but just to know the letters for a particular column number, so I think it would more likely be
- direct =SUBSTITUTE(ADDRESS(1,36,4),1,"") or
- via the column number being stored in a cell (eg A1) =SUBSTITUTE(ADDRESS(1,A1,4),1,"")
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,214,782
Messages
6,121,532
Members
449,037
Latest member
tmmotairi

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