vba 选择所有包含数据的单元格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/805960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Select all cells with data
提问by Marius
I have some data in an Excel Worksheet. I would like to select all the cells which contain data.
我在 Excel 工作表中有一些数据。我想选择所有包含数据的单元格。
For example, for a worksheet with data in cells A1, A2, A3, B1, B2, B3, C1, C2, and C3, how can I select just this 3x3 grid, and not the entire sheet?
例如,对于在单元格 A1、A2、A3、B1、B2、B3、C1、C2 和 C3 中包含数据的工作表,我如何只选择这个 3x3 网格,而不是整个工作表?
I am looking for something like ActiveSheet.SelectUsedCells.
我正在寻找类似的东西ActiveSheet.SelectUsedCells。
回答by RichieHindle
Here you go:
干得好:
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Or if you don't necessarily start at A1:
或者,如果您不一定从 A1 开始:
Range("C6").Select ' Select a cell that you know you populated'
Selection.End(xlUp).Select
Selection.End(xlToLeft).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
回答by Lunatik
You might also want to look at the CurrentRegionproperty. This will select a contiguous range that is bounded by empty cells, so might be a more elegant way of doing this, depending on the format of your worksheet.
您可能还想查看该CurrentRegion属性。这将选择一个以空单元格为边界的连续范围,因此可能是一种更优雅的方式,具体取决于工作表的格式。
For example:
例如:
Range("A1").CurrentRegion.Select

