+ Reply to Thread
Results 1 to 3 of 3

Thread: Conditionally hiding columns in Excel using VBA

  1. #1
    Registered User
    Join Date
    06-28-2011
    Location
    Vermont, USA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Conditionally hiding columns in Excel using VBA

    I am trying to hide columns when the value in a row is greater than value in a specfic cell. I modified code that I found on the forum to achieve this but somehow just can get it to fire. As I change the value in the specified cell all columns remain visible. The code I modified is shown below and comes from the following post.

    http://www.excelforum.com/excel-prog...ll-result.html

    I am a bit of a newbie at this but can generally follow what's going on in the code... the Dummies book helped a bunch!

    'Hides the a column when the value in row 6 (D6:Z6) is greater than value in cell B3
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Count < 1 Then Exit Sub
        If Union(Range("$D$6:$Z$6"), Target).Address = Range("$D$6:$Z$6").Address Then
            If Target.Value > Range("$B$3") Then Target.EntireColumn.Hidden = True
        End If
    End Sub
    Thanks very much for your help!

    --MrV

  2. #2
    Valued Forum Contributor
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    Excel 2010
    Posts
    522

    Re: Conditionally hiding columns in Excel using VBA

    try it
    'Hides the a column when the value in row 6 (D6:Z6) is greater than value in cell B3
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Union(Range("D6:Z6"), Target).Address = Range("D6:Z6").Address Then
        Target.EntireColumn.Hidden = Target.Value > Range("B3").Value
    End If
    End Sub

  3. #3
    Registered User
    Join Date
    06-28-2011
    Location
    Vermont, USA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Conditionally hiding columns in Excel using VBA

    Thanks very much for the suggestion. Unfortunately, it still does not fire. I have attached a copy of the file for your reference.

    Just to make sure I am understanding this correctly, the appropriate columns should disappear when I change the value in B3.

    Your help is appreciated!

    --MrV

    2012 QTD Forecast Tracking.xlsm
    Last edited by MrV; 01-17-2012 at 08:58 AM. Reason: adding attached file and tags

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0