我想在vba中使用Cells()函数选择I15:R15和I20:R20。无法使用Range,因为行号始终不同。
首先,我想将I15:R15和I16:R16复制并粘贴到一张纸上 接下来,我要复制并粘贴I15:R15和I17:R17,接下来,我要复制并粘贴I15:R15和I18:R18 .....等等。
如果我使用Range()函数,那么我不知道它是否总是复制I15:R15或I15:S15等,基本上I15是固定的,范围的右边(即列) R或S或T是否未确定。
答案 0 :(得分:0)
阅读完更新的帖子后,您正在寻找以下代码:
Dim Rng As Range
Dim i As Long
For i = 16 To 20
' Set a dynamic range of "I15:R15" and another row, starting from row 16 and incrementing untill 20
Set Rng = Application.Union(Range(Cells(15, "I"), Cells(15, "R")), Range(Cells(i, "I"), Cells(i, "R")))
Rng.Copy
' do your Paste code here
Set Rng = Nothing
Next i