• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Get last row excluding zero

YasserKhalil

Well-Known Member
Hello everyone
I am trying to get the last row in column B ..
Column B has formulas that may result in zeros ...
I need to find the last row that has non-zero value
Thanks advanced for help
 
Something like this?
Code:
Sub bCount()
Dim lRow As Long
Dim lvRow As Long
Dim i As Integer

lRow = Range("B" & Rows.Count).End(xlUp).Row

For i = lRow To 1 Step -1
    If Cells(i, 2).Value <> 0 Then
        lvRow = i
        Exit For
    Else
    End If
Next
MsgBox lvRow

End Sub
 
Great idea Mr. Chihiro to loop from last row till find the target and desired row
In fact I thought the same idea but I need a shortcut way to achieve that ..Is there an easy and short way to find the last row with non-zero values?
 
OOps, should be
Code:
Sub x()
    With Range("b1", Range("b" & Rows.Count).End(xlUp))
        MsgBox Evaluate("max(if((isnumber(" & .Address & "))*(" & .Address & "<>"""")*(" & .Address & "<>0),row(" & .Address & ")))")
    End With
End Sub
 
Mr. Jindon the first was working well with me .. What about the change in your last post .. as both are working ..
Which is better ?
 
Yes got your point now .. But I Liked first posted as it deals with strings aslo (both numbers and strings) .because in my file sometimes there are string results
 
Back
Top