+ Reply to Thread
Results 1 to 2 of 2

Hiding column based on formula result.

  1. #1
    Forum Contributor
    Join Date
    01-06-2004
    Location
    Carbondale CO
    Posts
    245

    Hiding column based on formula result.

    Hi,
    I'm trying to hide columns based on whether formulas in certain cells evaluate to zero. All of the cells are contained in named ranges that are all in the same row. I'm attempting to use the Union function to join those discontinuous named ranges into a single range, that I can then use to evaluate the individual cells with formulas, determine if they evaluate to Zero and if they do; then hide the entire column.
    The error is
    Run-time error "1004"
    Application-defined or Object-defined error

    Running Win XP & xl 2002

    Thanks in advance for any help

    Here is the code

    Private Sub HideColumns()

    Dim c As Range
    Dim d As Range

    Set d = Application.Union(Range("DFPlates_Array"), Range("RdWdPlates_Array") _
    , Range("TotalStudArray"))
    For Each c In d
    If c.Value = 0 Then
    c.EntireColumn.Hidden = True
    Else
    c.EntireColumn.Hidden = False
    End If
    Next c

    End Sub
    Casey

  2. #2
    Forum Contributor
    Join Date
    01-06-2004
    Location
    Carbondale CO
    Posts
    245

    Hiding column based on formula result.

    Hi again,
    I apologise for my previous post. After looking at the properties of the sheet I realized that it was protected. I inserted code to handle that and it fixed my problem. I'm posting my revised code in the hope it might help someone else.

    Revised Code

    Private Sub HideColumns()

    Dim c As Range
    Dim d As Range
    Application.ScreenUpdating = False
    Sheets("WALL TAKEOFF").Unprotect ("geekk")
    Set d = Application.Union(Range("DFPlates_Array"), Range("RdWdPlates_Array") _
    , Range("TotalStudArray"))
    For Each c In d
    If c.Value = 0 Then
    c.EntireColumn.Hidden = True
    Else
    c.EntireColumn.Hidden = False
    End If
    Next c
    Sheets("WALL TAKEOFF").Protect ("geekk"), DrawingObjects:=False, Contents:=True, Scenarios:= _
    False, AllowFiltering:=True
    ActiveSheet.EnableSelection = xlUnlockedCells 'Can't use for xl97/2000
    Application.ScreenUpdating = True
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1