[英]Excel VBA equivalent of ADDRESS function
I want to write this function in vba so that it gives me the cell id. 我想在vba中编写此函数,以便给我单元格ID。
=ADDRESS(1,2,4,TRUE,"Sheet1")
Does anyone know the VBA syntax for that? 有谁知道VBA语法吗? Thanks in advance. 提前致谢。
The normal way to do a similar thing in VBA would be either 在VBA中执行类似操作的正常方法是
Worksheets("Sheet1").Cells(1, 2).Address(RowAbsolute:=False, _
ColumnAbsolute:=False, _
External:=True)
which would return [TestWorkbook.xlsm]Sheet1!B1
or 这将返回[TestWorkbook.xlsm]Sheet1!B1
或
Worksheets("Sheet1").Cells(1, 2).Address(RowAbsolute:=False, _
ColumnAbsolute:=False, _
External:=False)
which would just return B1
. 这只会返回B1
。
There isn't a simple way of showing the worksheet name and cell, without also including the workbook name. 没有包含工作簿名称的简单方法来显示工作表名称和单元格。 A possible way would be 一种可能的方式是
"'" & Worksheets("Sheet1").Name & "'!" & Worksheets("Sheet1").Cells(1, 2).Address(RowAbsolute:=False, _
ColumnAbsolute:=False, _
External:=False)
(Obviously, if you use Worksheets("Sheet1").Name
then you may as well just use "Sheet1"
, but I wrote it that way so that you could use a variable instead of a hardcoded value. Edit: On rereading that last sentence, I realise how stupid it is - Worksheets(mySheetName).Name
is the same as mySheetName
, so just use "'" & mySheetName & "'!" & ...
) (很明显,如果您使用Worksheets("Sheet1").Name
那么您也可以只使用"Sheet1"
,但是我这样写,所以您可以使用变量而不是硬编码值。编辑:最后读一遍句子,我意识到它是多么愚蠢Worksheets(mySheetName).Name
与mySheetName
相同,因此只需使用"'" & mySheetName & "'!" & ...
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.