+ Reply to Thread
Results 1 to 7 of 7

Hiding Multiple Columns based on Cell Value

  1. #1
    Registered User
    Join Date
    02-28-2014
    Location
    Manchester, England
    MS-Off Ver
    Excel 2010
    Posts
    16

    Hiding Multiple Columns based on Cell Value

    Hi All,

    I am trying to hide columns in a range of data to get around the problem of my chart showing 8 potential lines on a line chart rather than 2-3 (depending on the data available).

    I have done some searching and this code works for me to hide a single column:

    Please Login or Register  to view this content.

    However, i'd like to also apply this to Column G when "C4" is 0, and Column H when "D4" is 0 etc.

    I tried to just copy and paste the code and make the changes but it wont allow me. I am using the code in the command window of the sheet so that Excel auto-calculates it each time, this way my chart will be dynamic on the screen.

    Can anyone suggest how I go about this? - I am not too familiar with VBA but trying to get onto a course (when it comes to loops and EndIfs etc, I get easily confused!)

    Thanks,
    Simon
    Last edited by simon_geoghegan; 01-12-2015 at 08:05 AM.

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Hiding Multiple Columns based on Cell Value

    You could try something like...
    Please Login or Register  to view this content.
    But you really should reconsider the location of the code - having it run every time a different cell is selected is not the best - no problem with a simple snippet, but if it grows it will start to affect things...

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Hiding Multiple Columns based on Cell Value

    Please use Code Tags:

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here


    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    02-28-2014
    Location
    Manchester, England
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Hiding Multiple Columns based on Cell Value

    Thankyou cytop - would you recommend assigning to a button or something instead?

    TMS - thankyou, noted and edited my original post.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Hiding Multiple Columns based on Cell Value

    noted and edited my original post.
    Thanks, appreciated

  6. #6
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Hiding Multiple Columns based on Cell Value

    I would usually put something like that in the Worksheet_Change event handler, but that will not fire if the cell changes because a formula recalculates - and you don't mention...

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Hiding Multiple Columns based on Cell Value

    Hi,

    Maybe the following

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ 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. [SOLVED] Hiding Multiple Rows and Columns based on a Cell Value
    By jshaw82 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-04-2014, 11:12 AM
  2. Need help hiding columns on multiple worksheets based on value in first sheet (VBA)
    By Blinky99 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-01-2014, 04:25 AM
  3. Hiding Columns based on Cell value
    By honger in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-28-2014, 02:44 PM
  4. Hiding different columns based on multiple cell values
    By shane1049 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-01-2013, 03:52 PM
  5. Hiding or showing rows based on contents of multiple columns
    By armsaw in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-07-2013, 02:11 AM

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