简体   繁体   中英

Ignoring specific rows with VBA Excel

I have a table in Excel like such, where the number of rows will vary each day:

Column A Column B Column C
Cell 1 Cell 2 Show
Cell 3 Cell 4 Show
Cell 5 Cell 6 Ignore

I am using vba to convert the range to a html table, and then email it. I have a helper column (Column C), and I want to use a formula there to filter out certain rows. However, that filter is not excluding hidden cells from being displayed in the html table.

I currently use this

Dim LastRow As Long LastRow = rInput.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

to find the last row of my table. This works great in projects where you want all of the table included. I tried to change it to Find("Ignore", which gets me Object variable or With block variable not set

I tried including 'SpecialCells(xlCellTypeVisible)' in my

ConvertRangeToHTMLTable(Sheet2.Range("$A:$J").Rows("5:" & LastRow), 5)

and using a filter to hide the 'Ignore' cells. But that did not stop them showing in the emailed html table.

You probably have some sort of loop which goes over the rows right? It will not automatically skip the hidden rows just because they are filtered out, you need to specifically tell it to skip them. You can do something like:

For Each r In myRange.Rows
    If Not r.EntireRow.Hidden Then
        doSomething
    End If
Next r

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM