【问题标题】:What is the best way to get the boundary of an array of data in VBA excel?在 VBA excel 中获取数据数组边界的最佳方法是什么?
【发布时间】:2016-07-02 12:21:14
【问题描述】:

我在 VBA 中编写了一个代码,用于获取 excel 中数据数组的最后一个边界。我假设数组以单元格“A1”开头:

Function getBoundary()

Dim boundaryPoint(2)
boundaryPoint(0) = Cells(Rows.Count, 1).End(xlUp).Row
boundaryPoint(1) = Cells(1, Columns.Count).End(xlToLeft).Column
getBoundary = boundaryPoint

结束函数

我想知道是否有更好的方法,以及我的代码是否经过优化。

【问题讨论】:

    标签: arrays vba excel boundary


    【解决方案1】:

    CurrentRegion怎么样:

    Dim boundaryPoint(2) As Long, r As Range
    
    Set r = Range("A1").CurrentRegion
    
    boundaryPoint(0) = r.Rows.Count
    boundaryPoint(1) = r.Columns.Count
    

    【讨论】:

    • 谢谢,正是我想要的:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-25
    • 2021-05-12
    • 2013-06-07
    • 1970-01-01
    • 1970-01-01
    • 2010-09-24
    相关资源
    最近更新 更多