+ Reply to Thread
Results 1 to 8 of 8

VBA to hide and unhide columns based on 2 criteria

  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)

    Please Login or Register  to view this content.
    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.

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,072

    Re: VBA to hide and unhide columns based on 2 criteria

    Hi & welcome to the board.

    Are S1 & T1 changed manually?
    Also please edit your post to include tags, the # icon in the reply/edit window.

  3. #3
    Registered User
    Join Date
    01-21-2019
    Location
    Goole
    MS-Off Ver
    2010
    Posts
    4

    Re: VBA to hide and unhide columns based on 2 criteria

    Hi,

    Sorry should have corrected that now.

    They're changed based on a drop down menu - if cell A1 contains specific text it returns 0 in S1 or 0 in T1.

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,072

    Re: VBA to hide and unhide columns based on 2 criteria

    Thanks for adding the code tags.

    From what you say it sounds like you have a formula in S1 & T1, so try
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-21-2019
    Location
    Goole
    MS-Off Ver
    2010
    Posts
    4

    Re: VBA to hide and unhide columns based on 2 criteria

    Thanks, it's almost there with that however when trying to hide L:Q it keeps P open.
    Is there anything that can be done for that?

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,072

    Re: VBA to hide and unhide columns based on 2 criteria

    Good point, try this instead
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-21-2019
    Location
    Goole
    MS-Off Ver
    2010
    Posts
    4

    Re: VBA to hide and unhide columns based on 2 criteria

    That's perfect - thank you for your help, much appreciated!

  8. #8
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,072

    Re: VBA to hide and unhide columns based on 2 criteria

    You're welcome & thanks for the feedback

+ Reply to Thread

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