Results 1 to 8 of 8

VBA to hide and unhide columns based on 2 criteria

Threaded View

Oliver1470 VBA to hide and unhide... 01-21-2019, 03:31 PM
Fluff13 Re: VBA to hide and unhide... 01-21-2019, 03:41 PM
Oliver1470 Re: VBA to hide and unhide... 01-21-2019, 03:53 PM
Fluff13 Re: VBA to hide and unhide... 01-21-2019, 03:58 PM
Oliver1470 Re: VBA to hide and unhide... 01-21-2019, 04:10 PM
Fluff13 Re: VBA to hide and unhide... 01-21-2019, 04:20 PM
Oliver1470 Re: VBA to hide and unhide... 01-21-2019, 04:25 PM
Fluff13 Re: VBA to hide and unhide... 01-21-2019, 04:33 PM
  1. #1
    Registered User
    Join Date
    01-21-2019
    Location
    Goole
    MS-Off Ver
    2010
    Posts
    4

    VBA to hide and unhide columns based on 2 criteria

    Hi everyone,

    I'm relatively new to VBA's so need a bit of help please...

    I'm looking to hide columns L through to Q when cell 'S1' returns 0 and unhide them all again when it goes blank. I've managed to use the below code to get this to work -
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

       If Range("S1").Value = 0 Then
            Columns("L").EntireColumn.Hidden = True
            Columns("M").EntireColumn.Hidden = True
            Columns("N").EntireColumn.Hidden = True
            Columns("O").EntireColumn.Hidden = True
            Columns("P").EntireColumn.Hidden = True
            Columns("Q").EntireColumn.Hidden = True
        Else
            Columns("L").EntireColumn.Hidden = False
            Columns("M").EntireColumn.Hidden = False
            Columns("N").EntireColumn.Hidden = False
            Columns("O").EntireColumn.Hidden = False
            Columns("P").EntireColumn.Hidden = False
            Columns("Q").EntireColumn.Hidden = False
        End If
    End Sub
    However I need another criteria in there too. If cell 'T1' returns 0 I would like to hide column P only and unhide when the cell goes blank. Both cells won't return 0 at the same time. I've tried adding another IF but seems to fail.

    Any help would be appreciated!
    Last edited by Oliver1470; 01-21-2019 at 03:49 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. hide & unhide columns on different sheet based on criteria
    By esbencito in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-25-2018, 02:31 AM
  2. Way to hide or unhide sheets based on selection criteria
    By jshrader in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-21-2016, 07:28 PM
  3. Hide/Unhide row based on given criteria w. no Trigger butn
    By m1zz13 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-18-2013, 06:31 AM
  4. Hide and unhide columns based on value of 0 or 1 (respectively) in cells G1:LG1
    By cplawren in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-22-2012, 01:58 AM
  5. Hide/Unhide Rows based on Criteria
    By Phillycheese5 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-04-2010, 02:11 PM
  6. Hide & Unhide columns based on a cell value
    By DaveNUFC in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-21-2010, 09:40 AM
  7. [SOLVED] Macro to hide and unhide based on criteria
    By dwight.yorke@gmail.com in forum Excel General
    Replies: 1
    Last Post: 06-05-2006, 03:10 PM

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