Hidden Property

Microsoft Office Web Components Visual Basic

expression.Hidden

expression    Required. An expression that returns a Range object.

Example

This example loops through a row that contains date values. When the month in the cell does not match the current month, the column is hidden. When the month matches the current month and the column is hidden, then the column is unhidden.

Sub Hide_Dates()
    Dim rngLoopRange
    Dim rngCurrCell
    Dim ssConstants

    Set ssConstants = Spreadsheet1.Constants

    ' Set range to loop through the range of contiguous
    ' cells in row 1 starting in column A.
    Set rngLoopRange = Spreadsheet1.ActiveSheet.Range("A1", _
            Spreadsheet1.ActiveSheet.Range("A1").End(ssConstants.xlToRight))

    ' Loop through the cells.
    For Each rngCurrCell In rngLoopRange

        ' Hide the column if the month in the current cell does
        ' not match the current month.
        If Month(rngCurrCell.Value) <> Month(Date) Then
            rngCurrCell.EntireColumn.Hidden = True

        ' If the month in the current cell matches the current month
        ' and the column is hidden, then unhide the column.
        ElseIf rngCurrCell.EntireColumn.Hidden Then
            rngCurrCell.EntireColumn.Hidden = False
        End If
    Next
End Sub