PDA

View Full Version : Solved: Hide row if ?



softman
10-12-2010, 03:52 AM
Hi, I have the following code below and it work in one row. I would like to knoe if it 's possibe were I have 2 rows with the following senario:

Colom: G And H
If colom G and H is 0 it stay
If colom G or H is 1 or 0 it stay
If colom Gor H is N/A or 0 it stay

But if colom G or H is both 1 it gets hide
If colom G or H is 1 or N/A it gets hide

Sub HURows()
BeginRow = 6
EndRow = 25
ChkCol = 7
For RowCnt = BeginRow To EndRow
If Cells(RowCnt, ChkCol).Value <= 1 Then
Cells(RowCnt, ChkCol).EntireRow.Hidden = True
Else
Cells(RowCnt, ChkCol).EntireRow.Hidden = False
End If
Next RowCnt
End Sub


Please find attached sample.

Simon Lloyd
10-12-2010, 04:38 AM
Hi, I have the following code below and it work in one row. I would like to knoe if it 's possibe were I have 2 rows with the following senario:

Colom: G And H
If colom G and H is 0 it stay
If colom G or H is 1 or 0 it stay
If colom Gor H is N/A or 0 it stay

But if colom G or H is both 1 it gets hide
If colom G or H is 1 or N/A it gets hide

Please find attached sample.You state:
If colom Gor H is N/A or 0 it stay then you state If colom G or H is 1 or N/A it gets hide you cant have both!

softman
10-12-2010, 05:54 AM
Hi Simon

What I want is if in any colom a 0 (zero) is selected it stay,
But if there is no 0 (zero) and the option is 1 with N/A or just 1 it hets hidden.

Hope this explain it better1

Simon Lloyd
10-12-2010, 08:36 AM
If all you want to see is zero's left then this will do:Dim i As Long
For i = Range("G" & Rows.Count).End(xlUp).Row To 1 Step -1
If Range("G" & i) = 1 Or Range("H" & i) = "N/A" Then
Rows(i).Hidden = True
End If
Next i

softman
10-13-2010, 11:31 PM
Hi Simon,

I have tried this but getting a Error message box that show only "400"

softman
10-13-2010, 11:35 PM
Hi Simon, Sorry, forget to commend out one previous line. Working fine. Many thanks.

softman
10-13-2010, 11:41 PM
Simon, How can I run this macro from a another sheeet. Meaning If I have this macro in a button on sheet 1 to run on sheet 2

softman
10-13-2010, 11:43 PM
Sorry agin, managed to get the answer, Solved

softman
10-14-2010, 12:06 AM
Hi Simom

I picked up something: when running the macro it works fine but this is what I get:

If colom G has a N/A and colom H a 1 it does not hide.
but it works the other way..

If colom G has a 1 and colom H a N/A it hides.

Same is working with 0, if N/A and 0 it work fine and does not hide
but if it is 0 and N/A it gets hiden, and should not.

Any idea?