vba 如何获取单元格的列字母(需要使其工作通过 Z 列,例如 AA、AB)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13788279/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can i get the Column letters of a cell (need to make it work past the Z column such as AA,AB)
提问by Viladimir
Possible Duplicate:
VBA function to convert column number to letter?
可能的重复:
VBA 函数将列号转换为字母?
I want to have the column letters past the Z column, there are many techniques for getting it before Z column but after Z, nothing seems to work Is there a way to do so?
我想让列字母越过 Z 列,有很多技术可以在 Z 列之前获取它,但在 Z 之后,似乎没有任何效果 有没有办法做到这一点?
回答by Dick Kusleika
Another method:
另一种方法:
Public Function ColumnLettersFromRange(rInput As Range) As String
ColumnLettersFromRange = Split(rInput.Address, "$")(1)
End Function
回答by Peter Albert
This should do the job:
这应该可以完成这项工作:
Function ColumnName(rng As Range) As String Dim s As String s = rng.Address(False, False) ColumnName = Left(s, Len(s) - Len(Format(rng.Row, "0"))) End Function
回答by NickSlash
Using worksheet functions to calculate the column letter isn't really a good plan. Using Peter Albert's VBA method is a much nicer way to do it!
使用工作表函数来计算列字母并不是一个好的计划。使用 Peter Albert 的 VBA 方法是一种更好的方法!
I had a go at making one using worksheet functions, just for fun :/
我尝试使用工作表函数制作一个,只是为了好玩:/
A-ZZ
A-ZZ
=IF(A1<27,CHAR(64+A1),IF(A1<703,CHAR(64+INT(A1/26))&CHAR(A1-INT(A1/26)+64),"TOO BIG!"))
A-XFD (doesn't work)
A-XFD(不起作用)
=IF(A1<27,CHAR(64+A1),IF(A1<703,CHAR(64+INT(A1/26))&CHAR(A1-(INT(A1/26)*26)+64),CHAR(64+INT(A1/676))&CHAR(64+(INT(A1-(INT(A1/676)*676))/26))&CHAR(64+INT(A1-((INT(A1-(INT(A1/676)*676))/26)*26)))))
The final one falls over trying to work out the 3rd character in the address, I just cant be bothered as using it is not a good plan!
最后一个在尝试计算地址中的第三个字符时失败了,我只是无法打扰,因为使用它不是一个好计划!