+ Reply to Thread
Results 1 to 9 of 9

A More Effficient Way to Iterate through and Show/Hide Columns?

  1. #1
    Registered User
    Join Date
    04-19-2013
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    8

    A More Effficient Way to Iterate through and Show/Hide Columns?

    Hi,

    I have some VBA I wrote that will iterate through a range of columns and, based on the value in a given row, will show or hide that column. The problem is, the number of columns I'm going through is quite large, and running the macro takes forever, and shuts down my system. It's literally faster to manually identify the columns to show and hide and do it myself.

    So, my question is: is there a more efficient way to do this?

    Here's the code I have now (ws is Worksheet object referencing the current tab):

    Please Login or Register  to view this content.
    As you can see from above, the columns are all dated, and each day I'm hiding the columns that are not for today and showing only the current day's columns.

    Any help on this would be appreciated!

    Thanks,

    Stephen
    Last edited by swatkinsjr; 07-12-2013 at 02:54 PM.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: A More Effficient Way to Iterate through and Show/Hide Columns?

    are there usually more columns to hide or show? have you turned off screenupdating while running the code?
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    04-19-2013
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: A More Effficient Way to Iterate through and Show/Hide Columns?

    Quote Originally Posted by JosephP View Post
    are there usually more columns to hide or show? have you turned off screenupdating while running the code?
    No, the number of columns usually stays pretty static. The only update, really, is the calculation for which ones are today's date.

    No I did not turn off screenupdating. I didn't know to do that. You think that'll speed up the code?

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: A More Effficient Way to Iterate through and Show/Hide Columns?

    I meant do you normally hide more of the data columns, or show more of them? it may be quicker to hide them all to start with then only show today's ones
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-19-2013
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: A More Effficient Way to Iterate through and Show/Hide Columns?

    Ah. Well, yes, most of the columns are hidden. Only a handful should show for any given day.

    Thanks! I'll make those changes and report back the results.

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: A More Effficient Way to Iterate through and Show/Hide Columns?

    Maybe?

    Please Login or Register  to view this content.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: A More Effficient Way to Iterate through and Show/Hide Columns?

    Are the columns to show grouped together?

    Is it always the same no of columns?

    Is there a way to identify the first column to hide, eg a header?
    If posting code please use code tags, see here.

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: A More Effficient Way to Iterate through and Show/Hide Columns?

    Please Login or Register  to view this content.



  9. #9
    Registered User
    Join Date
    04-19-2013
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: A More Effficient Way to Iterate through and Show/Hide Columns?

    Awesome. I think turning off Screenupdates was the thing. It works like a dream, now, and takes less than a couple seconds.

    Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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