如何在删除Activesheet
中的空白单元格后重新计算Activesheet
的lastRow,这样我会得到一个新的lastRow变量作为我的最大限制?我的数据来自网络查询。
示例:
但ActiveSheet
未刷新且lastRow未更新为650,我希望这些更新
答案 0 :(得分:1)
由于这是编写VBA for Excel时的常见要求,因此您可能希望编写一个可以在其他项目中重用的函数。这是一个例子:
Function get_end_row(ByVal column_with_data As Long) As Long
Dim last_row As Long
last_row = ThisWorkbook.ActiveSheet.Rows.Count
get_end_row = ThisWorkbook.ActiveSheet.Cells(last_row, column_with_data).End(xlUp).Row
''Note: in the line of code above you can replace xlUp with its hexidecimal value -> &HFFFFEFBE
''This will ensure the function works in other versions of Excel
End Function
以下是调用函数的示例:
Sub my_routine()
Dim endRow As Long
''The 1 being passed in the argument below is the first column number that your data is in
endRow = get_end_row(1)
Msgbox endRow
End Sub
在您的情况下,请确保在删除行后调用get_end_row()函数。