从第一行的单元格名称中找出Excel列的字符

我有一个看起来像这样的Excel表格。

在这里输入图像说明

标题名称位于第一行。 我想有一个VBA函数返回列号,给定单元格名称在第一行。 例如,getColumnNumber(“B Symbol”)应返回B getColumnNumber(“C Symbol”)应该返回C

我正在使用Excel 2016。

find文本,然后阅读地址。

 With Worksheets(1).Range("a1:z1") ' Set c = .Find("whatever you need to find", lookin:=xlValues) If Not c Is Nothing Then firstAddress = split(c.Address,"$")(0) msgbox firstAddress End If End With 

https://msdn.microsoft.com/en-us/vba/excel-vba/articles/range-find-method-excel

你不需要这个VBA。 下面的公式同样适用,任何VBA都使用基本相同的方法。

 =SUBSTITUTE(ADDRESS(1, MATCH("C Symbol", 1:1, 0), 4), 1, TEXT(,)) 

这是我自己的问题的答案,从泰迪的“修改”。 他的回答有一个小小的错误。

 With Worksheets(1).Range("a1:z1") ' Set c = .Find("whatever you need to find", lookin:=xlValues) If Not c Is Nothing Then firstAddress = split(c.Address,"$")(1) 'should be 1, not 0 msgbox firstAddress End If End With