+ Reply to Thread
Results 1 to 8 of 8

Hide columns

  1. #1
    Forum Contributor
    Join Date
    12-02-2008
    Location
    Brisbane
    MS-Off Ver
    2016
    Posts
    807

    Hide columns

    I am trying to hide some columns dependent on the contents of row 1 of each column. I have entered a zero in a number of the columns in the appropriate first row but absolutely nothing happens when I hit the button, Any help on where I'm going wrong is much appreciated.

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,681

    Re: Hide columns

    Nothing happened?
    How about
    Please Login or Register  to view this content.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Hide columns

    Hi Bob,

    I'd bet you have your code in the wrong place or by having it Private it doesn't work. See my example which seems to work like you want.
    http://www.your-save-time-and-improv...ivate-sub.html

    Hide Columns Code in Module.xlsm
    Last edited by MarvinP; 09-19-2016 at 10:37 PM.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Contributor
    Join Date
    12-02-2008
    Location
    Brisbane
    MS-Off Ver
    2016
    Posts
    807

    Re: Hide columns

    Thanks for your responses. I tried both codes - neither worked. I then tried them in new sheets in the same workbook and they both worked. I went back to the data sheet, deleted the button, inserted a new one and assigned the code. It now hides all the columns to, and including, the last column with "0" (the number zero with no speech marks). And leaves the sheet unprotected...

    The code I am using is:-

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    12-02-2008
    Location
    Brisbane
    MS-Off Ver
    2016
    Posts
    807

    Re: Hide columns

    Cancel comment about not protected - fixed that.

  6. #6
    Forum Contributor
    Join Date
    12-02-2008
    Location
    Brisbane
    MS-Off Ver
    2016
    Posts
    807

    Re: Hide columns

    Changed the last ActiveSheet.Unprotect to ActiveSheet.Protect and the sheet is not protected after the code has run. So this means the code is aborting before the end?

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,681

    Re: Hide columns

    Besides, Cells(1, i)=0 would return True when cells is empty, so
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    12-02-2008
    Location
    Brisbane
    MS-Off Ver
    2016
    Posts
    807

    Re: Hide columns

    I deleted the new button, went through and deleted all the code relating to it, entered it all again and it works! Looks like my error in assigning the wrong code but it all looked right. We live an learn. Thanks, rep added.

+ 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 Rows/Hide Columns Based on Value in Cell
    By brickwall823 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-24-2015, 02:42 PM
  2. VBA code to hide filtered columns (simple table 5 rows / 6 columns wide)
    By e2010 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-18-2014, 02:41 PM
  3. Hide columns using Columns' number
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-13-2014, 08:35 AM
  4. [SOLVED] Hide - Un Hide rows with empty columns
    By BDF in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 04-14-2014, 02:09 PM
  5. [SOLVED] Hide Columns based on level of access e.g. if "Read Only" Hide G:G
    By matrixpom in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-16-2013, 06:10 AM
  6. Hide columns through vba
    By grk_chakri in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-22-2012, 05:38 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