Use this vba code. Function Col_Letter_To_Number(ColumnLetter As String) As Double Dim cNum As Double 'Get Column Number from Alphabet cNum = Range(ColumnLetter & "1").Column 'Return Column Number Col_Letter_To_
Function GetColumnRef(columnIndex As Integer) As String Dim firstLetter As String Dim secondLetter As String Dim remainder As Integer Select Case columnIndex / 26 Case Is <= 1 'Column ref is between A and Z firstLetter = Chr(columnIndex + 64) GetColumnRef = firstLetter Case Else 'Column ...
2. 将指定的列序号转换为列名 FunctionGetColumnRef(columnIndexAsInteger)AsString DimfirstLetterAsString DimsecondLetterAsString DimremainderAsInteger SelectCasecolumnIndex/26 CaseIs<=1'Column ref is between A and Z firstLetter=Chr(columnIndex+64) GetColumnRef=firstLetter CaseElse'Column ref has two ...
2. 将指定的列序号转换为列名 FunctionGetColumnRef(columnIndexAsInteger)AsString DimfirstLetterAsString DimsecondLetterAsString DimremainderAsInteger SelectCasecolumnIndex/26 CaseIs<=1'Column ref is between A and Z firstLetter=Chr(columnIndex+64) GetColumnRef=firstLetter CaseElse'Column ref has two ...
按Alt+F11,打开VBA编辑器,单击菜单“插入→模块”,在右侧代码窗口中输入:Function ColumnLetter1(rng As Range) As String ColumnLetter1 = Replace(rng.EntireColumn.Cells(1).Address(, False), "$1", "")End Function 然后在A9单元格中输入公式 =ColumnLetter1(A9)或:Function ColumnLetter2...
按Alt+F11,打开VBA编辑器,单击菜单“插入→模块”,在右侧代码窗口中输入: Function ColumnLetter1(rng As Range) As StringColumnLetter1 = Replace(rng.EntireColumn.Cells(1).Address(, False), "", "")End Function 然后在A9单元格中输入公式 =ColumnLetter1(A9) ...
Excel VBA – To convert Column Number to Letter or Alphabet Lets assume the same example as above to understand this. We are going to pass 26 to this function & get column letter ‘Z’. Function Convert_Col_Number_To_Letter(ColumnNumber As Double) As String Dim sLetter As String 'Split...
在B列中我们利用自定义函数NZNumToLetter(),输出的结果: 二 根据字母给出列的数值 我们看一下这个工具的应用界面,如下图: 点击后代码会运行,程序中我给出的是”AG”列,要求求出这列的列数值,结果如下: 代码见程序文件:VBA_ConvertColumnNumberToLetter.xlsm...
在Excel VBA中,可以使用变量来表示行和列。 要表示行,可以使用Long类型的变量。示例代码如下: Dim rowNumber As Long rowNumber = 1 ' 表示第1行 复制代码 要表示列,可以使用String类型的变量。示例代码如下: Dim columnLetter As String columnLetter = "A" ' 表示A列 复制代码 你还可以使用Range对象来表示...
Column 1. 选择整列 Sub SelectEntireColumn() Selection.EntireColumn.Select End Sub 2. 将指定的列序号转换为列名 Function GetColumnRef(columnIndex As 1. Integer ) As String Dim firstLetter As String Dim secondLetter As String Dim remainder As Integer Select Case columnIndex / 26 Case Is <= ...