Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: my progress w/ Hide - UnHide Rows w/ Vba

  1. #1
    Guest

    Default

    Hi,

    In my haste i guess i didn't explain well
    enough what im trying to do. I'll try again:

    Say i have a range from A6:A1000, if in any
    row in column A witin A6:A1000 contains a "0"
    then that row is hidden. I can get it to work
    with this "lame" code but it's ridiculous
    as you can see....

    Private Sub CommandButton1_Click()
    If [A6,A7,A8,A9].Value > 0 Then
    Range("A6,A7,A8,A9").EntireRow.Hidden = False
    End If

    If [A6].Value = 0 Then
    Range("A6"). EntireRow.Hidden = True
    End If

    If [A7].Value = 0 Then
    Range("A7"). EntireRow.Hidden = True
    End If
    End Sub

    'It works "but it's obviously not the way to
    go to check 1,000 rows"

    Any help would be appreciated

    James



  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sunny, spring-like Hull
    Posts
    3,339
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    The following should work OK: -

    Private Sub CommandButton1_Click()

    Dim myRange As Range
    Dim c As Range

    Set myRange = Range("A6:A1000")
    Application.ScreenUpdating = False

    For Each c In myRange
    If c.Value = 0 Then
    c.EntireRow.Hidden = True
    Else:
    c.EntireRow.Hidden = False
    End If
    Next c

    Application.ScreenUpdating = True

    End Sub

    Ooops, forgot my screenupdating stuff .

    [ This Message was edited by: Mudface on 2002-03-09 14:01 ]

  3. #3
    New Member
    Join Date
    Mar 2002
    Location
    England
    Posts
    46
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Try this

    Public Sub HideRows()
    Dim c As Object
    For Each c In Range("$A$6:$A$1000")
    If c = "0" Then
    c.EntireRow.Hidden = True
    End If
    Next c
    End Sub


    [ This Message was edited by: waggy30 on 2002-03-09 14:08 ]

  4. #4
    Board Regular
    Join Date
    Feb 2002
    Location
    Huntington Beach, CA USA
    Posts
    327
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks, guys i appreciate it.

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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