Hide Rows when 3 conditions are met

J

Jeffrey

Hi All,

Is it possible to hide rows if 3 conditions are met.
Specifically i wish to hide row 5,6,7,and so on, when the
corresponding cell (D5,H5,L5),(D6,H6,L6),(D7,H7,L7),.... is zero (0).

Thanks in advance.

Jeff
 
O

Otto Moehrbach

Jeff
Yes, that is easy to do with VBA. However, Excel needs to know when you
want this to happen. Do you want to manually trigger a macro to look at all
the rows and do what you want? Or do you want Excel to monitor Columns D, H
and L, and check that row whenever the contents of any cell in Columns D, H,
or L is changed? And when you say "0" do you mean that the cell is blank
( a zero value) or do you mean that the cell content is, in fact, the
character "0"? HTH Otto
 
J

Jeffrey

Jeff
    Yes, that is easy to do with VBA.  However, Excel needs to knowwhen you
want this to happen.  Do you want to manually trigger a macro to look at all
the rows and do what you want?  Or do you want Excel to monitor ColumnsD, H
and L, and check that row whenever the contents of any cell in Columns D,H,
or L is changed?   And when you say "0" do you mean that the cell is blank
( a zero value) or do you mean that the cell content is, in fact, the








- Show quoted text -

Hi Mate,

Thanks for your response. I chose to trigger the macro manually, i
will just create a button to call this macro.
Yes if the cell has a numerical value of zero. "im not sure if zero is
a numerical value though : )".
Thanks in advance.

cheers.

Jeff
 
O

Otto Moehrbach

Jeff
Here is a macro that will do what you want. I took the simple way out
and just summed the 3 cells in each row and if the sum is zero, hide the
row. This will not work with your data if you have the possibility of
positive and negative numbers summing up to zero. The code will hide such a
row and you don't want that row hidden. Come back if you see that problem
with your data and I'll come up with another way of doing it. I assumed
that you had data in Column A and that your data starts in row 2. HTH Otto
Sub HideIfDHI()
Dim rRngDHL1 As Range
Dim rColA As Range
Dim c As Long
Set rRngDHL1 = Range("D1,H1,L1")
Set rColA = Range("A2", Range("A" & Rows.Count).End(xlUp))
Application.ScreenUpdating = False
For c = rColA.Count To 1 Step -1
If Application.Sum(rRngDHL1.Offset(c)) = 0 Then _
rColA(c).EntireRow.Delete
Next c
Application.ScreenUpdating = True
End Sub
Jeff
Yes, that is easy to do with VBA. However, Excel needs to know when you
want this to happen. Do you want to manually trigger a macro to look at
all
the rows and do what you want? Or do you want Excel to monitor Columns D,
H
and L, and check that row whenever the contents of any cell in Columns D,
H,
or L is changed? And when you say "0" do you mean that the cell is blank
( a zero value) or do you mean that the cell content is, in fact, the








- Show quoted text -

Hi Mate,

Thanks for your response. I chose to trigger the macro manually, i
will just create a button to call this macro.
Yes if the cell has a numerical value of zero. "im not sure if zero is
a numerical value though : )".
Thanks in advance.

cheers.

Jeff
 
O

Otto Moehrbach

Jeff
The code I gave you deletes the rows instead of hiding them. The macro
below hides them. Chalk it up to a senior moment. Otto
Sub HideIfDHI()
Dim rRngDHL1 As Range
Dim rColA As Range
Dim c As Long
Set rRngDHL1 = Range("D1,H1,L1")
Set rColA = Range("A2", Range("A" & Rows.Count).End(xlUp))
Application.ScreenUpdating = False
For c = rColA.Count To 1 Step -1
If Application.Sum(rRngDHL1.Offset(c)) = 0 Then _
rColA(c).EntireRow.Hidden = True
Next c
Application.ScreenUpdating = True
End Sub
Jeff
Yes, that is easy to do with VBA. However, Excel needs to know when you
want this to happen. Do you want to manually trigger a macro to look at
all
the rows and do what you want? Or do you want Excel to monitor Columns D,
H
and L, and check that row whenever the contents of any cell in Columns D,
H,
or L is changed? And when you say "0" do you mean that the cell is blank
( a zero value) or do you mean that the cell content is, in fact, the








- Show quoted text -

Hi Mate,

Thanks for your response. I chose to trigger the macro manually, i
will just create a button to call this macro.
Yes if the cell has a numerical value of zero. "im not sure if zero is
a numerical value though : )".
Thanks in advance.

cheers.

Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top