Find the First Non-Zero-Length Cell in a Range : Find « Forms « VBA / Excel / Access / Word






Find the First Non-Zero-Length Cell in a Range

 
Sub FirstNonZeroLength(Rng As Range)
    Dim myCell As Range
    myCell = Range("A1:E3")
    FirstNonZeroLength = 0#
    For Each myCell In Rng
        If Not IsNull(myCell) And myCell <> "" Then
            Debug.Print myCell.Value
            Exit Function
        End If
    Next myCell
    Debug.Print myCell.Value
End Function

 








Related examples in the same category

1.Consider only cells that contain data in the form of numbers, text, and formulas
2.Uses the Find method to reduce the number of cycles spent in VBA loops:
3.Working with Find and Replace
4.Continuing a Search with the FindNext Method and FindPrevious Method
5.Searching for and Replacing Formatting
6.Finding the Last Used Cell in a Column or Row
7.Ride the Range from the Bottom to Find Last Row