我在 Excel 中使用 VBA 范围时遇到一个小问题:
dim frameRefPoint As String
frameRefPoint = "4,4"
range(Cells(frameRefPoint).Offset(0,0), Cells(frameRefPoint).Offset(7, 7)).Interior ...
这并不符合我的预期。我认为指定 Range(Cells(4,4).Offset(0,0))
中的第一个单元格应该是“D4”,但是当我在代码中使用该范围时,第一个单元格该范围的单元格为“D1”~cells(1,4)。
cells(frameRefPoint) 的地址属性返回 $D$1。我在这里缺少什么?
最佳答案
您不能通过用中间逗号连接值来跨越两个参数(例如 .Cells(<row>, <column>)
)。仅仅让它“看起来”像您所编写的代码与合法代码不同。但是,您可以为每个参数使用变量。
dim r as long, c as long, frameRefPoint As string
r = 4
c = 4
cells(r, c).resize(7, 7) = "this works"
frameRefPoint = "4,4"
'split the string on the comma and convert teh text-that-looks-numbers to actual numbers
cells(int(split(frameRefPoint, ",")(0))), int(split(frameRefPoint, ",")(1)).resize(7, 7) = "this also works"
关于vba - 范围(单元格(...工作不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42739396/