【问题标题】:Excel VBA Range variable concatenationExcel VBA范围变量连接
【发布时间】:2018-07-10 18:22:46
【问题描述】:

我有以下 Excel VBA 代码块。 现在我必须将它们放入循环中并对其进行参数化。

Countruz2 = 2
 Countruz3 = Countruz2 + 13

Range("A2:A15").PasteSpecial (xlPasteValues)

以下是我尝试过的 - 3 个变体都失败了:无效使用属性错误。

'    Range ("A" & Countruz2 & ":" & "A" & Countruz3)                                    ' Invalid Use of Property

'    Range ("A" & Countruz2 & ":A" & Countruz3)                                         ' Invalid Use of Property

'    Range ("A" & Countruz2 & ":A" & Countruz2 + 13)                                    ' Invalid Use of Property

我们如何在 Excel VBA 的 Range 函数中处理此类连接和参数化?

提前感谢所有帮助。

编辑:

像这样连接它之后就可以工作了 -

X = "A" & Countruz2 & ":" & "A" & (Countruz2 + 13) 调试.打印 X Range(X).PasteSpecial (xlPasteValues)

还有其他优雅/简单的方法吗?

【问题讨论】:

  • 您只需要左上角的单元格作为粘贴的目的地。其他任何事情都是多余的,而且当您弄错目标大小或方向时,这只是另一个可能的错误。

标签: vba excel excel-formula ms-word


【解决方案1】:

试试这个

Countruz2 = 2
Countruz3 = Countruz2 + 13

Range("A" & Countruz2 & ":A" & Countruz3).PasteSpecial (xlPasteValues)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多