2013-03-02 3 views
1

Activesheet에서 빈 셀을 삭제 한 후에 Activesheet의 lastRow를 다시 계산하려면 어떻게합니까? 최대 제한값으로 새 lastRow 변수가 생깁니 까? 내 데이터는 웹 쿼리에서 가져온 것입니다.VBA에서 빈 셀을 삭제 한 후 ActiveSheet에서 lastRow를 다시 실행

예 :

  1. 이 데이터 소스 : 빈 셀 삭제 후 행 1360
  2. 수 : 수입 후 행 http://en.wikipedia.org/wiki/Polar_bear
  3. 수 650

그러나 ActiveSheet가 새로 고쳐지지 않습니다 lastRow가 650으로 업데이트되지 않았 으면 업데이트하고 싶습니다.

+5

코드에서 'ActiveSheet.UsedRange'를 사용하면 사용 범위가 다시 계산됩니다. – brettdj

답변

1

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() 함수를 호출해야합니다 다음은 예입니다.

+0

+1 멋진 휴대용 방법 – whytheq

관련 문제