Consulting

Results 1 to 9 of 9

Thread: Solved: Hide row if ?

  1. #1
    VBAX Regular
    Joined
    Mar 2010
    Posts
    49
    Location

    Solved: Hide row if ?

    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

    [VBA]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[/VBA]


    Please find attached sample.

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Quote Originally Posted by softman
    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!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    VBAX Regular
    Joined
    Mar 2010
    Posts
    49
    Location
    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

  4. #4
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    If all you want to see is zero's left then this will do:[VBA]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[/VBA]
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  5. #5
    VBAX Regular
    Joined
    Mar 2010
    Posts
    49
    Location
    Hi Simon,

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

  6. #6
    VBAX Regular
    Joined
    Mar 2010
    Posts
    49
    Location
    Hi Simon, Sorry, forget to commend out one previous line. Working fine. Many thanks.

  7. #7
    VBAX Regular
    Joined
    Mar 2010
    Posts
    49
    Location
    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

  8. #8
    VBAX Regular
    Joined
    Mar 2010
    Posts
    49
    Location
    Sorry agin, managed to get the answer, Solved

  9. #9
    VBAX Regular
    Joined
    Mar 2010
    Posts
    49
    Location
    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?
    Last edited by softman; 10-14-2010 at 12:17 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •