+ Reply to Thread
Results 1 to 10 of 10

Command Button to Hide rows based on a date range in Column A

  1. #1
    Registered User
    Join Date
    08-22-2014
    Location
    Kelowna, Canada
    MS-Off Ver
    Office 2010
    Posts
    30

    Command Button to Hide rows based on a date range in Column A

    In one spreadsheet, I want to have a command button that will hide all rows where the date column (column A) shows a date older than one week from today. When this button is clicked again, all rows will unhide again. Preferably the Command button title would change to reflect whether it is on the hide or show cycle (for example "Click to Hide all older than one week" and then "Click to Show all events")

    I know very little VBA code. Thanks.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Command Button to Hide rows based on a date range in Column A

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-22-2014
    Location
    Kelowna, Canada
    MS-Off Ver
    Office 2010
    Posts
    30

    Re: Command Button to Hide rows based on a date range in Column A

    Thank you stnkynts. I don't know how to program the command button however, with the code. Can you explain how to accomplish this?

  4. #4
    Registered User
    Join Date
    08-22-2014
    Location
    Kelowna, Canada
    MS-Off Ver
    Office 2010
    Posts
    30

    Re: Command Button to Hide rows based on a date range in Column A

    I got this to work, at least part of my original request. When tied to a command button, this code does indeed hide all records where the date is not from the past 7 days. It is fairly slow process, as it looks at every row individually and decides whether to hide the row or not. The spreadsheet it will be used for could have a lot of records, so this process will eventually take a lot of time to complete. Is there a quicker process than this? Also, I was hoping for the button to be programmed with a title that would say "Show Last Week" but after clicked the title would change to "Show All" and when clicked again, would reverse the hiding process.

  5. #5
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Command Button to Hide rows based on a date range in Column A

    Assuming you are using an ActiveX command button. If you are not, change it. I doubt it will take that long (I tested it on 20,000 rows and it took 1.1 seconds on an old computer). If it is a slow process it is probably because of other code you have added.

    Please Login or Register  to view this content.
    Last edited by stnkynts; 08-23-2014 at 06:47 PM.

  6. #6
    Registered User
    Join Date
    08-22-2014
    Location
    Kelowna, Canada
    MS-Off Ver
    Office 2010
    Posts
    30

    Re: Command Button to Hide rows based on a date range in Column A

    This is the code I have now. The original button was not Active X (didn't know the difference) but this one is. Tested it on only 17 rows and it took about 6 seconds. The button does change its caption based on how many times you click it, but when it is showing "Show All" it does not unhide the cells that were hidden on the first click. I really appreciate this. I've only really ever attached a macro to a button, never code.


    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Command Button to Hide rows based on a date range in Column A

    Submit your workbook.

  8. #8
    Registered User
    Join Date
    08-22-2014
    Location
    Kelowna, Canada
    MS-Off Ver
    Office 2010
    Posts
    30

    Re: Command Button to Hide rows based on a date range in Column A


  9. #9
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Command Button to Hide rows based on a date range in Column A

    It is slow because you have a ton of formulas and graphs on the worksheet "New Graphs" that are all calculating. Not going to be instantaneous with all the other stuff you got going on. Here are the updated options. Both took 7.3 seconds on 15,000 rows.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Note: It might be a little bit faster with regex but not by much. Its the graphs and formulas that are slowing you down.
    Last edited by stnkynts; 08-24-2014 at 04:10 PM.

  10. #10
    Registered User
    Join Date
    08-22-2014
    Location
    Kelowna, Canada
    MS-Off Ver
    Office 2010
    Posts
    30

    Re: Command Button to Hide rows based on a date range in Column A

    That is perfect. Thank you so much.

+ 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. How to hide command button based on another cell?
    By proepert in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-27-2014, 09:28 AM
  2. Macro command button to hide empty rows
    By djauncey in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-31-2012, 10:42 AM
  3. Hide Command Button & Rows
    By LaForgeOZ in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-01-2008, 08:08 PM
  4. [SOLVED] How do I hide a command button based on a condition?
    By ratttman@yahoo.com in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-03-2006, 09:50 AM
  5. Command Button to Hide/Unhide Rows
    By Bea in forum Excel General
    Replies: 4
    Last Post: 03-16-2006, 11:21 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