+ Reply to Thread
Results 1 to 9 of 9

Filter on today's date forward

  1. #1
    Registered User
    Join Date
    08-27-2007
    Location
    San Antonio Texas
    Posts
    41

    Filter on today's date forward

    Greetings - I'm working on cleaning up the code generated by the macro recorder for printing some reports, and I need to tell the report to print all rows where Column Q contains the words "Underwater Services" and Row "T" contains a date >= today.

    Here's the code I have presently at that section of the sub-routine:

    HTML Code: 
    I've tried replacing the 10/22/2007 with date and today, but all I'm getting are reports with headers and no data. For what it's worth I don't really care about Columns "R" or "S" in the AutoFilter - I've got those columns hidden anyway.

    If someone can offer suggestions that provide a cleaner way to filter on these two criteria and get the resuls described above I'd greatly appreciate it. Thanks in advance.

    Marcus

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Maybe

    Please Login or Register  to view this content.
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    08-27-2007
    Location
    San Antonio Texas
    Posts
    41

    cool

    Thanks - I thought this one would be easy for you.

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Glad it helped

    VBA Noob

  5. #5
    Registered User
    Join Date
    08-27-2007
    Location
    San Antonio Texas
    Posts
    41

    Still not working for some reason

    I didn't have a chance to plug the print code in until this evening, but when I did it still wants to print everything (going back to the beginning of the year).

    I've included the code I've got at this point below, along with copious comments. The code in question is the third section down, after the Dim Statement and report formatting. Any help would be appreciated. Thanks in advance - Marcus

    HTML Code: 

  6. #6
    Registered User
    Join Date
    08-27-2007
    Location
    San Antonio Texas
    Posts
    41

    I figured it out

    I think I might actually be getting this stuff.

    I wrote a little MsgBox routine to confirm for myself that the correct value was getting put in the 'Dt' variable (of course it was, but it was a good exercise for me), and then I used:

    HTML Code: 
    in place of:

    HTML Code: 
    and the report ran as intended. Thanks again for helping me get untracked.

    Marcus

  7. #7
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    Hi Marcus,

    Good to hear that you're getting into this stuff & Good luck with dates - they can be a nuisance :-)

    Your code can be streamlined a bit by removing all the ".select ... selection. ..." to something like:

    Please Login or Register  to view this content.
    I've changed the use of "columnwidth = 0" to "columns.hide = true" b/c that was what I'm used to (& I thought that it may be easier to unhide but when tested the use of either approach seems to make no difference).


    Further suggestions for speeding up code are out there eg Dave McRitchie has links to the below:

    http://www.avdf.com/apr98/art_ot003.html
    http://www.cpearson.com/excel/optimize.htm
    on his page:
    http://www.mvps.org/dmcritchie/excel...htm#speedupVBA


    hth
    Rob
    Last edited by broro183; 10-22-2007 at 04:01 AM.
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  8. #8
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Dates can be tricky in filter as this link shows. Look for
    Range.AutoFilter
    http://www.oaltd.co.uk/ExcelProgRef/...rogRefCh22.htm

    VBA Noob

  9. #9
    Registered User
    Join Date
    05-18-2016
    Location
    England
    MS-Off Ver
    2013
    Posts
    3

    Re: Filter on today's date forward

    For some reason it doesn't show any up and coming dates after today.
    I click a button on the sheet, it resets all filters, then it calls this routine:

    Sub UpComing_Work()
    '
    ' UpComing_Work Macro
    ' Up Coming shifts that are confirmed or proposed.
    '

    ' This section defines the variable Dt as a Date, and stores the current _
    ' date in the variable Dt
    Dim Dt As Date
    Dt = Date

    ' Print the Date in Cell D1:
    Range("D1").Value = Dt

    ' Show all entries after today's date:
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=2, Criteria1:=">=" & Dt, Operator:=xlAnd



    End Sub
    Last edited by Diesel9a1; 11-13-2018 at 07:40 AM.

+ 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