Welcome toExcel.Tips.Net
Tips.Net Home
ExcelTips Home
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Learn Access Now
Free Printable Forms
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Legal Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Wedding Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site
Filtering Columns for Unique Values
Printing Multiple Worksheets on a Single Page
You can easily determine the numeric column of cell by using the COLUMN function. All you need to do is put a formula like this in a cell, and the result is a value where A=1, B=2, etc.:
=COLUMN()
What if you want an alphabetic value, rather than a numeric value? This can be done in any of several different ways. For instance, the following formula will work very nicely for the first 26 columns, A through Z:
=CHAR(COLUMN()+64)
This works because the letters A through Z use character codes 65 through 90. When COLUMN returns a value for columns A through Z (1 through 26), this can be added to 64 to get the letters of those columns, 65 through 90.
Of course, this solution won't work if you want to know the letter designations of columns beyond Z. Versions of Excel prior to Excel 2007 can go up to column IV and Excel 2007 can go to column XFD. This formula will work for single- and double-character columns:
=IF(COLUMN()<27,CHAR(COLUMN()+64),CHAR((COLUMN()/26)+64)& CHAR(MOD(COLUMN(),26)+64))
As you can tell, when you get into multiple characters for a column, the formula gets long rather quickly. You can make the formula shorter by using a function other than COLUMN, however. Consider this formula, which relies primarily upon the ADDRESS function:
=LEFT(ADDRESS(1,COLUMN(),4),(COLUMN()>26)+1)
The ADDRESS function returns the address of a specific cell. In this case, it returns the address for the cell in the first row of the current column. Thus, if the formula is in cell BF27, it returns BF1. The formula uses the LEFT function to return the correct number of left-most characters in the address, minus the number 1 for the row.
Again, this approach will only work for columns that have up to two characters in them. If you are using Excel 2007, you need a different formula that will handle one, two, or three characters. This formula will work just fine:
=LEFT(ADDRESS(1,COLUMN(),4),LEN(ADDRESS(1,COLUMN(),4))-1)
An even shorter version of the formula relies upon the SUBSTITUTE function instead of the LEFT function:
=SUBSTITUTE(ADDRESS(ROW(),COLUMN(),4),ROW(),"")
This version uses the ROW function to put the address together, and then strips the ROW value out of the result of the ADDRESS function.
Of course, you can also use a macro-based solution, if you want to. The follow macro will work with one, two, or three character columns:
Function AlphaCol() As String
Dim J As Integer
Dim K As Integer
Dim iDiv As Integer
Dim sTemp As String
Application.Volatile
J = Selection.Column
iDiv = 26 ^ 2
sTemp = ""
While J > 0
K = Int(J / iDiv)
If K > 0 Then sTemp = sTemp & Chr(K + 64)
J = J - (K * iDiv)
iDiv = iDiv / 26
Wend
AlphaCol = sTemp
End Function
The macro is a user-defined function, which means that you can use it in your worksheets by simply adding this to any cell:
=AlphaCol()
A text string is returned, consisting of the column designation.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3254) applies to Microsoft Excel versions: 97 2000 2002 2003 2007
Make Home Buying Less Stressful! Why make home buying harder than it needs to be? Put your mind at ease—discover all the questions you need to ask to make the best buying decision.