Recursive Function to Convert Column Numbers to Letters

Category:
Office/VBA
Type:
Snippets
Difficulty:
Intermediate
Author:
Martin Kremer

Version Compatibility: Visual Basic 6

More information:
I needed to be able to convert an Excel column number into the letter designation as displayed in Excel. Every code snippet that I found involved a very complicated formula or relied on the built-in Excel ActiveCell.address() function. I wanted something simple and understandable, so came up with this recursive function. I have not done rigorous testing, but have tested the boundaries at a number of places (1, 26, 1222, 1223, etc) and several numbers posted in blogs with the complicated functions (217287 = LIKE, 1000 = ALL).

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: