简体   繁体   English

如何在VBA中选择特定的单元格?

[英]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.

相关问题 如何在 VBA 中移动特定值的单元格? - How do I move specific valued cells in VBA? 如何根据VBA中已命名的开始和结束单元格选择单元格范围? - How do I select a range of cells based on named start and end cells in VBA? 使用VBA,如何选择列中的单元格,直到命中设置的字符串 - Using VBA, how do I select cells in a column until I hit a set string 如何在excel vba中动态选择特定的单元格范围? - how to select a specific cells range dynamically in excel vba? 如何计算 VBA 中非空白的单元格? - How do I count cells that are not blank in VBA? 如何使用VBA或公式对Excel范围内具有特定值且具有注释的单元格进行计数? - How do I count cells with in a range in excel with specific value that has a comment using vba or formula? 如果在vba中包含特定字符串,我如何循环遍历单元格并创建新行? - How do I loop through cells and create a new row if it contains a specific string in vba? 如何使用excel VBA以特定方式复制和粘贴单元格,然后删除某些行? - How do I copy and paste cells and then delete certain rows in a specific way using excel VBA? 如何跳过某些单元格 VBA xlPasteValues 命令并将公式保持在特定范围内 - How do I skip certain cells VBA xlPasteValues command and keep the formulas in specific range 在 Excel 中,如何使用 VBA 仅复制具有特定顺序的所需单元格 - In Excel how do I copy only wanted cells with specific order with VBA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM