vba - 范围(单元格(...工作不正确

标签 vba excel range

我在 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/

相关文章:

vba - 使用 VBA 在 Office 中压缩图像

excel - 获取 ID 序列中的第一个和最后一个数字以及产品名称并显示在另一个工作表中

vba - LibreOffice 中的宏可将 Impress 幻灯片的背景更改为纯黑色

linux - 将输出转换为 Excel 工作表的脚本

excel - 更改Excel中的默认值 'delimiters'

vba - 使用 End 与 Unload me 关闭表单

string - 如何使用 Excel 函数获取字符串的最后一个字符?

php - 获取符合特定范围条件的可能组合(大小为 N)

javascript - 获取相对于父元素的点击范围

vba - Excel 中的多个图表