从列号获取列名? [英] Get column name from column number?

查看:93
本文介绍了从列号获取列名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在工作表上有几个命名的列.我想将列号发送到一个函数,该函数将返回列名.

I have several named columns on a sheet. I want to send the column number to a function that will return the column name.

例如,如果列1名为"apple",我想将列号1传递给一个返回列名"apple"的函数.我的尝试:

For example, if column 1 is named "apple", I want to pass the column number 1 to a function that returns the column name "apple". My attempt:

Function getColName(colNumber As Integer) As String
'return column name when passed column number

    getColName = Cells(1, colNumber).Column.Name

End Function

如何使此代码正常工作?

How can I get this code to work?

推荐答案

尝试以下方法:

set cell_address = Worksheet("Sheet1").Cells(1,1)
MsgBox cell_address.address(RowAbsolute:=False, ColumnAbsolute=False) 

'返回A1 您也可以在Range("A1")中使用它并获得更多功能.

'returns A1 You can use it in Range("A1") as well and get more functionality.

**Note**: RowAbsolute:=False, ColumnAbsolute=False are optional 

有关更多信息:

https: //msdn.microsoft.com/zh-CN/vba/excel-vba/articles/range-address-property-excel

https://msdn.microsoft.com/en-us/vba/excel-vba/articles/range-address-property-excel

对于非vba: https://exceljet.net/formula/convert-column-number-to-字母

这篇关于从列号获取列名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆