in Excel VBA, you can use the .Range method to get the number, for example:
Dim rng as Range Dim vSearchCol as variant 'your input column Set rng.Thisworkbook.worksheets("mySheet").Range(vSearchCol & "1:" & vSearchCol & "1")
Then use the .column property:
debug.print rng.column
if you need the full code see below:
Function ColumnbyName(vInput As Variant, Optional bByName As Boolean = True) As Variant Dim Rng As Range If bByName Then If Not VBA.IsNumeric(vInput) Then Set Rng = ThisWorkbook.Worksheets("mytab").Range(vInput & "1:" & vInput & "1") ColumnbyName = Rng.Column Else MsgBox "Please enter valid non Numeric column or change paramter bByName to False!" End If Else If VBA.IsNumeric(vInput) Then ColumnbyName = VBA.Chr(64 + CInt(vInput)) Else MsgBox "Please enter valid Numeric column or change paramter bByName to True!" End If End If End Function
V. Wolf Jul. 19 '16 at 12:22 2016-07-19 12:22
source share