Consulting

Results 1 to 10 of 10

Thread: Solved: VBA Hide Rows if Cell Value is #N/A

  1. #1
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location

    Solved: VBA Hide Rows if Cell Value is #N/A

    [vba]
    Sub hide_if_error()
    Dim MyCell As Range, Rng As Range
    Set Rng = Range("c8:c27")
    For Each MyCell In Rng
    If MyCell = IsError??? Then
    MyCell.EntireRow.Hidden = True
    End If
    Next MyCell
    End Sub
    [/vba]
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub hide_if_error()
    Dim MyCell As Range, Rng As Range
    Set Rng = Range("c8:c27")
    For Each MyCell In Rng
    If IsError(MyCell) Then
    MyCell.EntireRow.Hidden = True
    End If
    Next MyCell
    End Sub
    [/vba]

    But hiding errors seems like a bad idea to me.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    Quote Originally Posted by xld

    But hiding errors seems like a bad idea to me.
    Same here but as it was requested by the user so I must give it ... How can I apply this to work in multiple worksheets (Sheet20 upto sheet80) in a command button
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Same range for each sheet, or different? Set sheets, or variable?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    same range on each sheet...
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub hide_if_error()
    Dim MyCell As Range, Rng As Range

    For Each sh In ActiveWorkbook.Worksheets
    Set Rng = sh.Range("c8:c27")
    For Each MyCell In Rng
    If IsError(MyCell) Then
    MyCell.EntireRow.Hidden = True
    End If
    Next MyCell
    Next sh
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Contributor
    Joined
    Jul 2004
    Location
    Gurgaon, India
    Posts
    148
    Location
    Hi,

    I think a loop can be avoided. See

    [vba]On Error Resume Next
    Range("c8:c27").SpecialCells(xlCellTypeFormulas, 16).EntireRow.Hidden = True
    Range("c8:c27").SpecialCells(xlCellTypeConstants, 16).EntireRow.Hidden = True
    On Error GoTo 0[/vba]
    HTH

  8. #8
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    Solved
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  9. #9
    VBAX Expert
    Joined
    Aug 2007
    Location
    Windermere, FL, a 'burb in the greater Orlando metro area.
    Posts
    567
    Location
    Krishna,

    Why not use 'xlErrors' instead of the number 16 (its numeric equivalent) since the term is more discriptive?
    [vba]On Error Resume Next
    Range("c8:c27").SpecialCells(xlCellTypeFormulas, xlErrors).EntireRow.Hidden = True
    Range("c8:c27").SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.Hidden = True
    On Error GoTo 0[/vba]
    Thanks,
    Ron
    Windermere, FL

  10. #10
    VBAX Contributor
    Joined
    Jul 2004
    Location
    Gurgaon, India
    Posts
    148
    Location
    Quote Originally Posted by RonMcK
    Krishna,

    Why not use 'xlErrors' instead of the number 16 (its numeric equivalent) since the term is more discriptive?
    [vba]On Error Resume Next
    Range("c8:c27").SpecialCells(xlCellTypeFormulas, xlErrors).EntireRow.Hidden = True
    Range("c8:c27").SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.Hidden = True
    On Error GoTo 0[/vba]
    Thanks,
    Well, that was recorded macro. Will keep in mind.

Posting Permissions

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