+ Reply to Thread
Results 1 to 8 of 8

VBA code to hide rows based on a date

  1. #1
    Registered User
    Join Date
    10-24-2011
    Location
    Orlando, FL
    MS-Off Ver
    Office 365 for Business
    Posts
    87

    VBA code to hide rows based on a date

    Hello: I have been almost an entire day at the computer looking for a VBA code to hide rows. Every one I have tried has failed.
    In the attached, I would like a macro that copies 'Booked Orders' worksheet, creates a copy named 'Orders In Whse'. It should be able to over-write 'Orders In Whse' every time the macro is run.

    Next I would like it to look at columns B & C, and hide the rows where both date columns are an earlier or same date as the current date (Now).

    The code I had started:
    Please Login or Register  to view this content.
    I have attached a sample file.
    Thank you so much!!!

    P.S. If anybody could recommend a book for a VBA novice like me, I would appreciate it!
    Attached Files Attached Files

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: VBA code to hide rows based on a date

    Sounds easy enough, but could you clarify two things first?

    Is there a reason you need to copy the sheet rather than just copy the data over?
    Is there a reason you need to hide the rows rather than just copy the relevant rows (the ones that would be visible after hiding the others) to the second sheet?

    BSB

  3. #3
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: VBA code to hide rows based on a date

    For example, try this:
    Please Login or Register  to view this content.
    BSB

  4. #4
    Registered User
    Join Date
    10-24-2011
    Location
    Orlando, FL
    MS-Off Ver
    Office 365 for Business
    Posts
    87

    Re: VBA code to hide rows based on a date

    Hi Badly: I just want it to look nice. I was using a formula to copy data, but it was not presentable as a report for employees to use. That's why I thought of copying the main report (worksheet) first.
    Rows do not need to be hidden, just want to see the appropriate ones.
    Thanks for the code below! I will try it and report back!

  5. #5
    Registered User
    Join Date
    10-24-2011
    Location
    Orlando, FL
    MS-Off Ver
    Office 365 for Business
    Posts
    87

    Re: VBA code to hide rows based on a date

    Badly: I tried your code, and it worked! I did give an incorrect operator for column "C", it should be >=.
    Something did come up, though. I realized that some values in Column C in my full worksheet will be blank. In that case, I still want them returned in the "Orders in Whse" sheet.
    So, I tried to alter the code as below, but it did not return any rows. Any suggestions to include blanks in column C as well?
    Thanks so much!
    Please Login or Register  to view this content.

  6. #6
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: VBA code to hide rows based on a date

    You were so close! You need an OR rather than an AND. In your attempt you're checking if C is both >= today's data AND blank, and that just cannot happen.
    Change the AND to OR and all will be fine.

    Please Login or Register  to view this content.
    BSB
    Last edited by BadlySpelledBuoy; 04-22-2021 at 02:12 AM.

  7. #7
    Registered User
    Join Date
    10-24-2011
    Location
    Orlando, FL
    MS-Off Ver
    Office 365 for Business
    Posts
    87

    Re: VBA code to hide rows based on a date

    It Worked!!!! Thank you so much for all of your help!

  8. #8
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: VBA code to hide rows based on a date

    No problem at all. Glad I could help out.

    BSB

+ 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] How to Hide Rows based on date
    By nsmjc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2018, 10:19 PM
  2. [SOLVED] VBA Code to hide rows based on cells value
    By pipoliveira in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 08-07-2018, 12:15 PM
  3. [SOLVED] Need to tweak code...Hide Rows Based on Cell Value
    By kmlloyd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-21-2015, 11:05 AM
  4. [SOLVED] Hide rows based on cell value - VBA code
    By phbryan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-21-2015, 12:38 PM
  5. VBA code to hide/show rows based on value in each row
    By KEM4321 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-11-2012, 01:19 PM
  6. Code to show/hide rows based on Y
    By Justinmih in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-03-2011, 06:12 PM
  7. Hide rows based on date
    By SSGMiami in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-02-2009, 03:13 PM

Tags for this Thread

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