I have a worksheet which has many formulas and I need the following to happen: when this worksheet is used, and some cells on different rows are filled with a number other than 0
, the rows which contain cells with 0
, to hide automatically. And this should happen every time that worksheet is used, with different values.
About the attached example:
- The value that changes is in column
B
D
,E
andF
are merged cells on each row-
talking about the attached example: I need rows with
Text2
,Text 4
andText 5
to be hidden automatically, because inB
column the value is zero for these rows.
-
IMPORTANT! – at each use of the worksheet, the rows that have
0
in columnB
are different. Not always the same. And also, this automatization must apply only to a certain selection in the document (let's say from rows45
to135
).
Best Answer
This is similar to another answer but testing shows performance is nearly 1.5 orders of magnitude (70x) faster by doing all the property changes in two transactions; one each for
hideRange.EntireRow.Hidden = True
andunhideRange.EntireRow.Hidden = False
.There are three constants at the beginning of the file used to specify the column, starting row, ending row and value to hide on. The OP values have been plugged in.
Copy the following code into the specific vba WorkSheet module. This code will not work from a regular module. Press Alt-F11 to open the Visual Basic Editor. Press Ctrl-R to focus/open the Project Explorer pane. Navigate to
VBAProject(<file name>)
,Microsoft Excel Objects
and open theSheet#(<sheet name>)
where the hidden rows reside.Regular Module Changes
Me
objects to a specific sheet reference.Worksheets("Worksheet Name")
criteria for one worksheet.