Results 1 to 5 of 5

Hiding and Unhiding Entire Columns based on Cell Reference

Threaded View

montego Hiding and Unhiding Entire... 07-02-2010, 12:31 PM
shg Re: Hiding and Unhiding... 07-02-2010, 12:33 PM
montego Re: Hiding and Unhiding... 07-02-2010, 12:58 PM
shg Re: Hiding and Unhiding... 07-02-2010, 01:14 PM
montego works 07-02-2010, 01:25 PM
  1. #1
    Registered User
    Join Date
    06-30-2010
    Location
    Tucson, Arizona
    MS-Off Ver
    Excel 2007
    Posts
    58

    Hiding and Unhiding Entire Columns based on Cell Reference

    Hello All,

    I would like some help on VBA code for hiding certain columns based off of a cell reference. This question has been solved here, but I now want to connect the macro to a button as seen here. The cell to be referenced is in row 3, (in columns B case, B3) and is a conditional IF statement based on another sheet in the workbook. The possible results are 0 and "".

    The First Button Labaled Relevant Data (this is the button I want to be able to click and have it hide coloumns which the third row is equal to 0). This is the one I need help on. I currently have

    Sub CommandButton1_Click()
        Application.ScreenUpdating = False
        Dim Target As Range
        Set Target = Range("B3:BA3")
        If Target.Count > 1 Then Exit Sub
        If Union(Range("$B$3:$BA$3"), Target).Address = Range("$B$3:$BA$3").Address Then
            If Target.Value = 0 Then Target.EntireColumn.Hidden = True
        End If
        Application.ScreenUpdating = True
    End Sub
    '
    The Second button is labaled "Show all Cells". This button Works, and I do not need help with it, but the code is displayed below

    Sub CommandButton2_Click()
         Application.ScreenUpdating = False
         Range("B3:BA3").EntireColumn.Hidden = False
         Application.ScreenUpdating = True
    End Sub
    '
    Thank you in advance!
    Last edited by montego; 07-02-2010 at 01:30 PM.

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