Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel VBA Filtered/Visible Cell

Tags:

excel

vba

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

like image 390
babsdoc Avatar asked Jan 05 '13 15:01

babsdoc


People also ask

How do I sum only filtered visible cells in Excel VBA?

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.

Does VBA work on hidden cells?

Your macro can access any cells in the workbook, unless the worksheet containing the cell is hidden.


1 Answers

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?

like image 186
whytheq Avatar answered Sep 27 '22 20:09

whytheq