获取 VBA excel 中数据数组边界的最佳方法是什么?
What is the best way to get the boundary of an array of data in VBA excel?
我在 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
结束函数
我想知道是否有更好的方法来做,我的代码是否优化了。
怎么样CurrentRegion
:
Dim boundaryPoint(2) As Long, r As Range
Set r = Range("A1").CurrentRegion
boundaryPoint(0) = r.Rows.Count
boundaryPoint(1) = r.Columns.Count
我在 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
结束函数
我想知道是否有更好的方法来做,我的代码是否优化了。
怎么样CurrentRegion
:
Dim boundaryPoint(2) As Long, r As Range
Set r = Range("A1").CurrentRegion
boundaryPoint(0) = r.Rows.Count
boundaryPoint(1) = r.Columns.Count