devxlogo

Converting Numbers to Column Names in Excel 2007

While converting to Excel 2007, I had to update the column-number-to-string code in my program to handle columns of 703 and above (AAA). I found Yassine Moe’s code and simplified it. Here are the results:

Function ExcelColNonRec(ByVal intCol As Long) As String    While (intCol > 0)        intCol = intCol - 1        ExcelColNonRec = Chr(65 + (intCol Mod 26)) + ExcelColNonRec        intCol = intCol  26    WendEnd FunctionCorresponding MFC version:CString ColumnNumberToLetter( long lColumnNumber ){	CString sColumn;	while ( lColumnNumber )	{		lColumnNumber--;		sColumn = static_cast< TCHAR >( _T( 'A' ) + ( lColumnNumber % 26 ) ) +sColumn;		lColumnNumber /= 26;	}	return ( sColumn );}

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Engineering Leaders Spot Weak Proposals

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.