• 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.

loop through visible cells

Monty

Well-Known Member
Hello Experts.

Iam looking out for a small piece of code which can loop through visible cells...


Thanks in advance.
 
Hello Monty
Suppose you have numbers in A2:A20 for example and you have filtered numbers to show only numbers greater that 5 ..
You can try the following
Code:
Sub PrintVisibleUsingLoop()
    Dim cel As Range
   
    For Each cel In Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row)
        If cel.EntireRow.Hidden = False Then
            Debug.Print cel
        End If
    Next cel
End Sub

Or without loop you can use special cells
Code:
Sub PrintVisibleUsingSpecialCells()
    Dim cel As Range

    For Each cel In Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row).SpecialCells(xlCellTypeVisible)
        Debug.Print cel
    Next cel
End Sub
 
Back
Top