2016-08-19 2 views
1

나는 데이터를 마지막 행을 찾을 열과 관련하여 데이터가 들어있는 첫 번째 셀을 찾는 방법은 무엇입니까?

lastRowIndex = .Cells(.Rows.Count, "A").End(xlUp).row 

을 사용하고 있습니다.

어떻게 첫 행을 찾습니까? 내가 activesheet.usedrange와 함께 몇 가지 코드를 발견하지만 그것은 b 열 첫 번째 데이터가 두 번째 행에서 시작하기 때문에 나를 위해 작동하지 않습니다하지만 열에는 4 행에서 시작합니다. 나는 다음과 같은 나에게 4 번

+1

'firstRowIndex = .Cells (1, "A"). 끝 (xlDown) .row' 및 가능한 행 처리 –

답변

0

CountA()를 사용하지 않고 다른 버전을 발견하는 기능입니다 필요 통과 열

에 데이터가없는 경우 0을 반환

Function firstrow2(col As Range) As Long 
    Dim f As Range 
    Set f = col.Find("*", after:=col.Cells(col.Parent.Rows.Count)) '<--| look for any value in given column from its row 1 (included) downwards 
    If Not f Is Nothing Then firstrow2 = f.Row '<--| if found then return its row index 
End Function 

당신은 다음을 사용할 수 있습니다 조금 더 강력하게하고 잘못된 통과 범위 (열 후가 아닌 전체 열 또는 넓은)를 처리해야합니다

Function FirstRow(col As Range) As Long 
    Dim f As Range 
    With col.Columns(1).EntireColumn 
     Set f = .Find("*", after:=.Cells(.Rows.Count)) '<--| look for any value from row 1 (included) 
    End With 
    If Not f Is Nothing Then FirstRow4 = f.Row '<--| if found then return its row index 
End Function 
1
Dim col As Range 
Set col = Columns(10) 

If Application.CountA(col) > 0 Then 
    Debug.Print "first data: " & col.Find("*", after:=col.Cells(Rows.Count)).Row 
Else 
    Debug.Print "no data" 
End If 
관련 문제