简体   繁体   English

Excel VBA向下选择所有单元格

[英]Excel VBA Select all cells down

I'm looking to select every cell below a certain cell (not only in my list). 我想选择某个单元格下方的每个单元格(不仅在列表中)。 I know of xldown, but this doesn't work in the instance of blanks, which occur in my list. 我知道xldown,但这不适用于在我的列表中出现的空白实例。

Is this possible? 这可能吗?

The follow will select all cells from A1 down to the last cell in column A that's not empty : 以下将选择从A1到A列中最后一个不为空的所有单元格的所有单元格:

Sub select_all()
  Range(Cells(1, 1), Cells(Range("A1000000").End(xlUp).Row, 1)).Select
End Sub

You can modify the column / range to fit in your situation. 您可以修改列/范围以适合您的情况。 Noted that it is hardcoded to assume 1000000 or less rows being used. 请注意,硬编码假定使用的行数为1000000或更少。

This will select A9 to column A the last row with data: 这将选择A9到A列的最后一行数据:

Range("A9:A" & range("A" & rows.Count).End(xlUp).Row).select

Just change A and 9 to whatever column and row you want. 只需将A和9更改为所需的任何列和行即可。

I am interested to know what your next line of code is though as .select can most probably be ommited and the command can be performed directly without a select. 我很想知道您的下一行代码是什么,因为.select很可能会被省略,并且无需选择即可直接执行命令。

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

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