Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50068

need help re hiding rows in a range based on cell contents

$
0
0
In Excel 2010 I have a single-column range (1x50) whose cells each contain zero up to a few short alphanumeric snippets separated by spaces (eg: etf, ad, etf 3m5, f hei7, etfg ...etc.). I need a VBA function which, when aimed at the range, hides (or un-hides) every row in which a specific snippet is found. If the snippet is "etf", both the cell with "etf" and the cell with "etf 3m5" above would be hidden, but the cell with "etfg" would not. If no snippet is provided, every row in the range is hidden.

The pseudo-code below lays out the logic I think, but I need help translating that into Excel 2010 VBA code. Assistance very much appreciated. - Jim

Code:

function HideTheseRows( theRange as range, theSnippet as string, hideIt as boolean) as boolean
        if LENB(theSnippet)=0 then
                hide all of the rows in the range
        else
                for each cell in(theRange)
                        if cell contains(theSnippet) then
                                cell.row.hidden=hideIt
                        end if
                end for
        end if
        HideTheseRows=TRUE
end sub


Viewing all articles
Browse latest Browse all 50068

Trending Articles