+ Reply to Thread
Results 1 to 8 of 8

Auto hide/unhide columns in excel

  1. #1
    Registered User
    Join Date
    09-27-2013
    Location
    Brisbane
    MS-Off Ver
    Excel 2007
    Posts
    4

    Auto hide/unhide columns in excel

    Hi. First thread. Ever.
    I've searched high and low for coding to automatically hide/unhide columns (range = h7:av8) with a given value ("" or #N/A). This is to reduce the number of series on an associated column chart.
    They all look a little like this:
    Please Login or Register  to view this content.
    But, alas. Not one of the "solved" suggestions have worked for me. Any tips?

    Moderator Note:
    Pls use code tags around your code next time as per forum rules.
    Last edited by Fotis1991; 09-27-2013 at 02:13 AM.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Auto hide/unhide columns in excel

    Hi, BRJ,

    please wrap up your procedure with code-tags for better readability.

    Donīt use the Select at the end of the first codeline (will throw up an exception). Maybe itīs not working because you loop through cells in the code but you refer to Selection in the Sample:

    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    09-27-2013
    Location
    Brisbane
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Auto hide/unhide columns in excel

    Hi Holger.
    Thanks for your reply. I've tried, but not working. I think I'm in over my head. I'm using macro-enabled book and pasting directly into VB "view code", I've tried 'general' and 'worksheet'. I could be doing a million things wrong (learning as I go) so I don't expect miracles from anyone. Thanks for trying though.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Auto hide/unhide columns in excel

    Hi, BRJ,

    maybe this may help
    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button
    The Worksheet_SelectionChange-event I mentioned would to be placed behind the sheet you want to monitor and would be started with each movement of the cursor.

    If you canīt get it to work maybe attach a sample of your workbook with no sensible data to have a look at for further help.

    Ciao,
    Holger

  5. #5
    Registered User
    Join Date
    09-27-2013
    Location
    Brisbane
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Auto hide/unhide columns in excel

    Thanks Holger.
    Seems to get me a little closer to the solution I'm after. Here's a couple of points:
    1. When anything changes on the worksheet, can the macro run again (ie- all the columns should be available to reappear)?
    2. Ideally (I didn't mention this on my initial question), I would love the code to search H7:av7 and then h8:av8 (if blanks appear in ONLY ONE range, then the event is NOT triggered)
    I know these things are a lot to ask, I don't mind if it's too much trouble for you. Thanks.
    Last edited by BRJ; 09-27-2013 at 01:49 AM.

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Auto hide/unhide columns in excel

    Hi, BRJ,

    do the cells in the areas mentioned rely on formulas or do you enter the values by hand? That would determine if to use the Worksheet_Change-Event (manual entry or query) or Worksheet_Calculate which would be triggered by formulas and any new calculation.

    If the values are entered manually:
    Please Login or Register  to view this content.
    Default way for a For Each...Next loop is to move right till it reaches the last column and then proceed in the next row of code with the first column.

    Ciao,
    Holger

  7. #7
    Registered User
    Join Date
    09-27-2013
    Location
    Brisbane
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Auto hide/unhide columns in excel

    The cell values are calculated by an index formula, triggered by a combo box.

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Auto hide/unhide columns in excel

    Hi, BRJ,

    any chance to trigger the start of the code from that combobox? The formulas could be calculated first and then evaluated from the macro. Iīm afraid there is no shortcut to cutting down the number of cells to check with formulas as I think all of the cells are formulas. Depending on the usual estimated number of columns to be shown maybe Find could be used to cut down the number of cells to loop but I would need to know what the book/sheet looks like in order to give more than just basic hints on how to proceed.

    Ciao,
    Holger

+ 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. Auto Hide/Unhide rows in Excel based on radio button selection
    By awill110 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-30-2013, 03:05 PM
  2. [SOLVED] Auto unhide/hide columns
    By FragaGeddon in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-30-2012, 05:50 PM
  3. Excel Hide/Unhide Rows/Columns
    By jregan in forum Excel General
    Replies: 4
    Last Post: 08-03-2010, 11:55 AM
  4. How to auto hide and unhide columns using 1 and 2 icons
    By R. Rebello in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-12-2006, 03:15 AM
  5. [SOLVED] Auto hide/Unhide columns
    By Vespaguy in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-20-2006, 01:40 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