+ Reply to Thread
Results 1 to 6 of 6

Macro filtering all dates out, not leaving ones required.

  1. #1
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Macro filtering all dates out, not leaving ones required.

    Attached Macro should find all records on the DATABASE SHEET that meet three Criteria (Sample Point, Category and Measure) between a Start and End date set on the MEASURE sheet.

    But it filters out ALL the DATABASE dates, generating a RunTime 1004 error message when the Code then tries to copy the (incorrectly) filtered range to the MEASURE sheet,

    Please Login or Register  to view this content.
    Hope someone can see the error?

    All solutions, suggestions and alternatives welcome

    Ochimus
    Attached Files Attached Files

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,885

    Re: Macro filtering all dates out, not leaving ones required.

    Few things.
    1. Sheet3.Select & Selection.Autofilter
    Avoid using Selection in code. Unless it's absolutely necessary. As it's prone to error and causes slowdown in code. Also, AutoFilter shouldn't be applied to sheet. But to range.

    2. Rows.Count doesn't need "." in front.

    3. Your criteria range reference is off. Below should be looking at C column. Not D, as per your worksheet. As well, C6 isn't exact match to column value (field 3). You'll need to concatenate with wild card.
    Please Login or Register  to view this content.
    Finally, I'd recommend using Advanced Filter Copy rather than Autofilter for this sort of data extraction.
    Ex:
    Please Login or Register  to view this content.
    See attached set up.
    Attached Files Attached Files
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Macro filtering all dates out, not leaving ones required.

    Your filter criteria is referencintg the wrong cells on sheet1.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro filtering all dates out, not leaving ones required.

    I'll post the treated sample next #.
    Last edited by xladept; 01-22-2019 at 12:53 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro filtering all dates out, not leaving ones required.

    Here it is:
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: Macro filtering all dates out, not leaving ones required.

    Many thanks to everyone who responded so quickly and effectively.

    Astounding that in all the years of using Excel I have not come across Advanced Filter Copy before - so that's another technique to master!

    Can now mark this as Solved, and on to the next challenge.

    Ochimus

+ 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] Macro not filtering between recognised dates
    By Ochimus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-10-2018, 10:45 AM
  2. Calculating number of days between dates but leaving blank if...
    By FHVS in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-11-2015, 12:35 AM
  3. complex filtering/macro required to only show columns with certaing data. HELP!
    By kasjes in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-09-2013, 09:28 AM
  4. [SOLVED] Help with filtering dates using a macro.
    By jcranst in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-28-2013, 08:40 AM
  5. [SOLVED] When filtering repeated data, leaving the title(header) alone without deleting it
    By exlgh91 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-13-2013, 12:58 PM
  6. Filtering between dates and time macro excel
    By elriverita in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-13-2012, 08:16 AM
  7. Adding Dates but leaving a cell blank
    By dodger999 in forum Excel General
    Replies: 5
    Last Post: 08-21-2009, 03:35 PM

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