范围(单元格(…工作不正确

我在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 “〜细胞(1,4)。

单元格的地址属性(frameRefPoint)返回$ D $ 1。 我在这里错过了什么?

您不能跨越两个参数(例如.Cells(<row>, <column>) )通过连接值与临时逗号。 只是使它看起来像你的代码是不一样的合法代码。 但是,您可以为每个参数使用variables。

 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" 
 Range(Cells(CInt(Split(frameRefPoint, ",")(0)), CInt(Split(frameRefPoint, ",")(1))).Offset(0, 0), Cells(CInt(Split(frameRefPoint, ",")(0)), CInt(Split(frameRefPoint, ",")(1))).Offset(7, 7)).Interior....