【问题标题】:Select all cells with data选择所有包含数据的单元格
【发布时间】:2020-02-29 16:35:07
【问题描述】:

我在 Excel 工作表中有一些数据。我想选择所有包含数据的单元格。

例如,对于在单元格 A1、A2、A3、B1、B2、B3、C1、C2 和 C3 中包含数据的工作表,如何只选择这个 3x3 网格,而不是整个工作表?

我正在寻找类似ActiveSheet.SelectUsedCells 的东西。

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    给你:

    Range("A1").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    

    或者如果你不一定从 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
    

    【讨论】:

      【解决方案2】:

      您可能还想查看CurrentRegion 属性。这将选择一个以空单元格为界的连续范围,因此可能是一种更优雅的方式,具体取决于工作表的格式。

      例如:

      Range("A1").CurrentRegion.Select
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-03-31
        • 1970-01-01
        • 2012-05-18
        • 2015-06-20
        • 1970-01-01
        • 2013-02-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多