Code to hide specific rows?

laxster

Registered User.
Local time
Today, 15:42
Joined
Aug 25, 2009
Messages
145
I have a table that is calculated out. However, cases arise in which 2 cells have a #VALUE! and one cell has a #NA!. This behavior is normal and expected. What I'd like to do is be able to hide the entire row if those conditions are met.

How would I go about doing this? I'm trying to piece together something in VBA, but it's pretty laughable.
 
This from help shows the codes required to handle errors
Code:
This example displays a message if the active cell on Sheet1 contains a cell error value. You can use this example as a framework for a cell-error-value error handler.

Worksheets("Sheet1").Activate
If IsError(ActiveCell.Value) Then
    errval = ActiveCell.Value
    Select Case errval
        Case CVErr(xlErrDiv0)
            MsgBox "#DIV/0! error"
        Case CVErr(xlErrNA)
            MsgBox "#N/A error"
        Case CVErr(xlErrName)
            MsgBox "#NAME? error"
        Case CVErr(xlErrNull)
            MsgBox "#NULL! error"
        Case CVErr(xlErrNum)
            MsgBox "#NUM! error"
        Case CVErr(xlErrRef)
            MsgBox "#REF! error"
        Case CVErr(xlErrValue)
            MsgBox "#VALUE! error"
        Case Else
            MsgBox "This should never happen!!"
    End Select
End If

you would need to use it like so I guess tho in my simple example I am only looking at 1 cell, you will probably need to iterate through a column or whole spreadsheet.

Code:
If IsError(Range("d1").Value) Then
 If Range("d1").Value = CVErr(xlErrValue) Then
 Range("d1").EntireRow.Hidden = True
 End If
End If


Brian
 
Thanks! I ended up with this, which does exactly what I need:

Code:
Option Explicit
Sub Marine()
Dim r As Range

Set r = Cells.SpecialCells(xlCellTypeFormulas, 16)

r.EntireRow.Hidden = True

Set r = Nothing
End Sub
 

Users who are viewing this thread

Back
Top Bottom