+ Reply to Thread
Results 1 to 7 of 7

VBA to display data based on dates

  1. #1
    Registered User
    Join Date
    10-09-2012
    Location
    Scotland
    MS-Off Ver
    Excel 2016
    Posts
    48

    VBA to display data based on dates

    Hi folks,

    First post so be gentle

    Need to add a few buttons to my sheet so that I can essentially filter the data quickly with one click and shows the relevant rows.

    VBA Buttons seem the best idea.

    I need to write the VBA code so that when button 81 is clicked, it filters the sheet to show work outstanding based on dates in K5:K171. Basically anything with blank or a date between today and 01/01/2005.

    Second button is to show work due again using data in K5:K171. Work due will be anything with a date between 01/01/2005 and 30 days in the future.

    If only I had to use VBA everyday this would be so much easier - I use it so infrequent I tend to forget how to do things

  2. #2
    Registered User
    Join Date
    10-09-2012
    Location
    Scotland
    MS-Off Ver
    Excel 2016
    Posts
    48

    Re: VBA to display data based on dates

    Noone got any ideas?

  3. #3
    Forum Contributor stojko89's Avatar
    Join Date
    05-18-2009
    Location
    Maribor, Slovenia
    MS-Off Ver
    MS Office 365
    Posts
    913

    Re: VBA to display data based on dates

    Try using the AutoFilter

  4. #4
    Registered User
    Join Date
    10-09-2012
    Location
    Scotland
    MS-Off Ver
    Excel 2016
    Posts
    48

    Re: VBA to display data based on dates

    Autofilter works great for today ... and if I'm the only one using it.

    Other folks who dont know what to select with autofilter may be using it and its so I can have a single button click for them in order that they can see what work is needing done now.

  5. #5
    Registered User
    Join Date
    10-09-2012
    Location
    Scotland
    MS-Off Ver
    Excel 2016
    Posts
    48

    Re: VBA to display data based on dates

    Got this to almost work - needs to be tweaked but not sure where I went wrong....

    Sub Button81_Click()
    Application.ScreenUpdating = False
    Dim r As Range
    Set myRange = ActiveSheet.Range("K7:K171")
    For Each r In myRange
    If r.Value > [TODAY()+30] Then
    r.EntireRow.Hidden = True
    End If
    If r.Value < [TODAY()-3650] Then
    r.EntireRow.Hidden = True
    End If
    If r.Value <> [BLANK] Then
    r.EntireRow.Hidden = False
    End If
    Next
    Application.ScreenUpdating = True
    End Sub

  6. #6
    Forum Contributor stojko89's Avatar
    Join Date
    05-18-2009
    Location
    Maribor, Slovenia
    MS-Off Ver
    MS Office 365
    Posts
    913

    Re: VBA to display data based on dates

    Try putting it like this:
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor stojko89's Avatar
    Join Date
    05-18-2009
    Location
    Maribor, Slovenia
    MS-Off Ver
    MS Office 365
    Posts
    913

    Re: VBA to display data based on dates

    Or like this
    Please Login or Register  to view this content.

+ 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