Suppose I have 10 rows of data. I apply some filter to the data and row numbers 7 and 9 are filtered OR visible.
I want to loop through the data (10 Rows) and output the string "Is Visible" in a blank column (suppose Column C), only for the Visible rows (i.e. Range C7 and Range C9).
1. In a blank cell, C13 for example, enter this formula: =Subtotal(109,C2:C12) (109 indicates when you sum the numbers, the hidden values will be ignored; C2:C12 is the range you will sum ignoring filtered rows.), and press the Enter key.
Your macro can access any cells in the workbook, unless the worksheet containing the cell is hidden.
Choose some of the first 10 rows to hide, and then try running this
Option Explicit
Sub CheckIfVisible()
Dim i As Integer, x As Integer
x = 0
For i = 1 To 10
With Excel.ThisWorkbook.ActiveSheet
If .Rows(i).EntireRow.Hidden Then
Else
.Cells(15 + x, 1) = "Row " & i & "is visible"
x = x + 1
End If
End With
Next i
End Sub
Is this the sort of loop you're looking for?
Maybe you can show us your Loop so we can see where your problem is?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With