简体   繁体   English

动态.Range()函数Excel宏

[英]Dynamic .Range() function Excel Macro

I was using the function .Range("some_cell") as follows: 我正在使用函数.Range(“ some_cell”)如下:

For i = 1 to 100
   CurrentCell = 3 + i
   ThisWorkbook.Sheets("Sheet1").Rage("JCurrentCell")
Next i

However, Rage("JCurrentCell") is not allowed, what can I do to dynamically change this range from (ex: J1, J2, J3, J4, ... Jn) 但是,不允许Rage("JCurrentCell") ,我该怎么做才能动态更改此范围(例如:J1,J2,J3,J4,... Jn)

Put your CurrentCell variable outside quotation marks: 将您的CurrentCell variable放在引号之外:

For i = 1 to 100
   CurrentCell = 3 + i
   ThisWorkbook.Sheets("Sheet1").Range("J" & CurrentCell)
Next i

Pleas keep in mind, too: 恳求也要牢记:

  1. use Range() object name, not Rage() 使用Range()对象名称,而不使用Rage()
  2. this line ThisWorkbook.Sheets("Sheet1").Range("J" & CurrentCell) is not complete at the moment, it doesn't do anything. 此行ThisWorkbook.Sheets("Sheet1").Range("J" & CurrentCell)目前尚未完成,它没有执行任何操作。

you can also use cells 你也可以使用细胞

For i = 1 to 100
   ThisWorkbook.Sheets("Sheet1").Cells(i + 3, "J")
Next i

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM