[英]How do I select specific cells in VBA?
Basically I need to select specific cells on an excel sheet in vba. 基本上我需要在vba中的excel工作表上选择特定的单元格。 For example the code should be able to select a5, a10, a15. 例如,代码应该能够选择a5,a10,a15。 I do not want the cells in between them, just the ones I listed. 我不希望它们之间的单元格只是我列出的那些单元格。 Is there a specific function that will do this? 有特定的功能可以做到这一点吗? It seems like .Range could only take start cell and ending cell. 似乎.Range只能采用开始单元格和结束单元格。
You'd use this: Range("A5,A10,A15").Select
您将使用: Range("A5,A10,A15").Select
To add additional cells, just use more commas. 要添加其他单元格,只需使用更多逗号。
Alternately, you can utilize the Union method to join multiple range objects into a single Range object. 或者,您可以利用Union方法将多个范围对象合并为一个Range对象。
Note that it is generally not a good idea to select cells in VBA as nearly everything can be done without selection. 请注意,在VBA中选择单元通常不是一个好主意,因为几乎所有操作都无需选择即可完成。 This is a frequent mistake made by people new to VBA due to generated macros (Record Macro) recreating what you do rather than the result you want. 这是VBA新手经常犯的错误,这是由于生成的宏(记录宏)重新创建了您要做的事情,而不是您想要的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.