简体   繁体   中英

first Occurrence Of Non Blank Cell vba

I am trying to write VBA code which works on my Excel sheet.

Range("A65536").End(xlUp).Row gives me the row number of the last non blank cell. similarly i am trying to get the row number of the first non blank cell in that particular column. Thanks in advance. madhu

You can use the same function, just check to see if the first row is blank.

Dim firstRow as Integer

If ActiveSheet.Range("A1").value = "" Then
    firstRow = ActiveSheet.Range("A1").End(xlDown).Row
Else
    firstRow = 1
End If

If the first row is not blank and you use the End(xlDown) call you won't get the first non-empty cell you will get the last non-empty cell before the first blank cell.

您还可以使用IsEmpty(cell)函数,该函数返回布尔值true / false。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM