Excel 용 VBA를 작성할 때 공통 요구 사항이므로 다른 프로젝트에서 다시 사용할 수있는 함수를 작성하는 것이 좋습니다. 여기
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() 함수를 호출해야합니다 다음은 예입니다.
코드에서 'ActiveSheet.UsedRange'를 사용하면 사용 범위가 다시 계산됩니다. – brettdj