Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50112

Last non-zero number in column where column contains numbers and letters

$
0
0
I have a column with zeros, non-zero numbers, and strings. I need to determine the row number that the last non-zero number is in. This previous thread provided a good example, but it wasn't quite what I was looking for. http://www.excelforum.com/excel-prog...ero-value.html

Here is the code that thread suggested:
Code:

Sub NonZeroCell()
    Dim rRng As Range, rFound As Range
   
    Set rRng = Range("B1", Cells(Rows.Count, "B").End(xlUp))
    Set rFound = rRng(rRng.Rows.Count, rRng.Columns.Count)
   
    Do Until rFound > 0
        Set rFound = rRng.Find(What:="*", After:=rFound, LookIn:=xlFormulas, LookAt _
        :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
    Loop
   
    MsgBox rFound.Address
End Sub

The biggest problem is that the "*" returns the last of EVERYTHING that is not a zero, including strings, which is what I don't want. It should only be the last non-zero number. It's also been a while since I had to program in VBA, so I'm also not entirely sure how to set the row number as a variable using these commands.

I have no attachment to the above code, so it can be completely scrapped in favor of something else. Thanks in advance.

Viewing all articles
Browse latest Browse all 50112