1、首先在开发工具中打开VBA编辑器
2、在单元格区域当中输入一些内容作为例子
3、在VBA编辑器中插入模块
4、在模块当中输入如下代码,然后运行Function Col(Optional Col鲍伊酷雪Num) As String '返回指定列的列号,参数为可选 App造婷用痃lication.Volatile If Not VBA.IsNumeric(ColNum) Then Coll="" If VBA.IsNumeric(ColNum) Then '如果输入的是数字 If ColNum > 16384 Or ColNum < 1 Then Col="超出范围": Exit Function '不能大于16384或者小于1 Col=Left(Cells(1, ColNum).Address(0, 0), 1-(ColNum > 26)-(ColNum > 702)) '取得列号 Exit Function End If '如果不输入参数,则返回当前列的列号 Col=Left(Cells(1, ActiveCell.Column).Address(0, 0), 1 – (ActiveCell.Column > 26)-(ActiveCell.Column > 702)) '取得列号End Function
5、在单元格A1中输入公式“=col()”,因省略了参数,则单元格显示当前列的列号“A”