Column Name to Column Number

Home/Excel VBA/Column Name to Column Number

Column Name to Column Number is nothing but converting Excel alphabetic character column name to column number. Most of the time while automating many tasks it may be required. Please find the following details about conversion of column name to column number. You can also say column string to column number. Or get alphabetic character to column number using Excel VBA. Please find the following different strategic functions to get column name to column number.

PREMIUM TEMPLATES LIMITED TIME OFFER

ON SALE80% OFF

50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates


Column Number to Column Name

Column Name to Column Number: By Referring a Range

Please find the following details about conversion from Column Name to Column Number in Excel VBA. Here we are referring a range.

'Easiest Approach: By Referring a Range
Function fnLetterToNumber_Range(ByVal strColumnName As String)
fnLetterToNumber_Range = Range(strColumnName & "1").Column
End Function

Column Name to Column Number: Example and Output

Please find the below example code. It will show you how to get column number from column name using Excel VBA. In the below example “fnLetterToNumber_Range” is the function name, which is written above. And “D” represents the Column name and “fnLetterToNumber_Range” function parameter.

Sub sbLetterToNumber_ExampleMacro1()
MsgBox "Column Number is : " & fnLetterToNumber_Range("D")
End Sub

Output: Press ‘F5’ or Click on Run button to run the above procedure. Please find the following output, which is shown in the following screen shot.

Column Name to Column Number

Column Name to Column Number: Using Len function and For loop

Please find the following details about conversion from Column Name to Column Number in Excel VBA. Here we are referring using a ‘Len’ function and For loop.

 
'Using Len functions and For loop
Function fnLetterToNumber_LenForLoop(ByVal strColumnName As String)
fnLetterToNumber_LenForLoop = 0
For i = 1 To Len(strColumnName)
fnLetterToNumber_LenForLoop = (Asc(UCase(Mid(strColumnName, i, 1))) - 64) + fnLetterToNumber_LenForLoop * 26
Next i
End Function

Column Name to Column Number: Example and Output

Please find the below example code. It will show you how to get column number from column name using Excel VBA. In the below example “sbLetterToNumber_ExampleMacro” is the function name, which is written above. And “DA” represents the Column name and “sbLetterToNumber_ExampleMacro” function parameter. The function has written using for loop. When you run the above example procedure, you will see the following output.

Sub sbLetterToNumber_ExampleMacro()
MsgBox "Column Number is : " & fnLetterToNumber_LenForLoop("DA")
End Sub

Output: Press ‘F5’ or Click on Run button to run the above procedure. Please find the following output, which is shown in the following screen shot.

Column Name to Column Number_Op2

More about Column Number to Column Name Conversion

Here is the link to more about how to convert column number to column name using VBA in Excel.

Column Number to Name Conversion

LIMITED TIME OFFER
By |June 10th, 2015|Excel VBA|0 Comments

About the Author:

Excel VBA Developer having around 8 years of experience in using Excel and VBA for automating the daily tasks, reports generation and dashboards preparation. Valli is sharing to helps us automating daily tasks.

Leave A Comment


Related pages


how to draw pivot tableexcel password vbarun vba codeasap utilities 64 bit downloadaptitude test questions and answers for freshers pdfautomation testing interview questions and answers for freshersexcel lookup arraywhile loop in excelcells worksheetsvlookup in excel vba with examplesscrum excel templateexcel vba status bar progressexcel access vbatelecom testing interview questions answers pdfcapacity model template excelexcel insert row vbaexcel vba stringremove duplicate lines in exceltick box in excel 2007lookup function excel 2007vba getrowsdata mining interview questions and answers pdfprotect an excel workbookvlookup with if conditionvb define arraycheckbox vba excelcombine data from multiple excel filesexcel vba lookup functionexcel functions tutorial with examplesexcel pivot table vbahow to apply validation in excelexcel vba matchexcel unlock password protected sheetsumif example in excelhow to select a range in vbadocmd.opentabledml ddlvba open csvhow to merge tabs in excelremove duplicates excel 2010vba close excel applicationexcel vba choosevba excel cell formatautomation testing interview questions and answers pdf free downloadhow to hide and unhide columns in excel 2007multi select listboxloop in excel formulavba & operatorexamples of vlookup in excelcopy sheet vbashortcut for inserting a row in excelvba string arrayexcel 2007 vba exampleshow to delete selected rows in excelhow to program macros in exceltrim vba excelvlookup in microsoft excelrgb excel vbarefresh all pivot tablesadd developer tab to the ribbonunprotect excel vba project passwordprotected excel sheet unprotectexcel to csv convertermicrosoft excel vba programming for dummies 2010project management tracking excelxlworkbook saveasvba formulaexcel vba function rangevba destinationhow do i create a pivot table in excel 2007create folder vbasample dashboards in excelexcel vba option button value