+ Reply to Thread
Results 1 to 16 of 16

Splitting Data to separate files - does not work with "date" as the filter

  1. #1
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    Splitting Data to separate files - does not work with "date" as the filter

    I am looking to run the attached file but to split the sheets based on the "Date" field, which seems to cause issues.

    This is a weekly file that would have to be run, so rather than focusing on the date (because in reality the date is not important, it is only used as a split filter), I was thinking that if there was a way to essentially Take the unique dates that appear,
    sort them from smallest to largest, and then replace the smallest with a "1", next "2", etc... up to 5.

    Or even with a name? Ship Date 1 will always be a thursday, 2 a friday, 3 Monday, 4 Tuesday, 5, wednesday.

    I have found that if i manually put in a number or type in a day name that the split works fine... even if i convert the date to a number it works fine... it is only when it is in date format that it does not work.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,792

    Re: Splitting Data to separate files - does not work with "date" as the filter

    How about in a blank column
    =WEEKDAY(O3,14)
    Change O3 to where the date is.
    It will return 1 for Thu 2 for Fri, 5 for Mon etc.

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,785

    Re: Splitting Data to separate files - does not work with "date" as the filter

    How about adding a column to your table and putting this formula in V5 and copying down then using column V to filter and split your data

    =IF(WEEKDAY([@ShipDate])=5,1,IF(WEEKDAY([@ShipDate])=6,2,IF(WEEKDAY([@ShipDate])=2,3,IF(WEEKDAY([@ShipDate])=3,4,5))))
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

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

    Re: Splitting Data to separate files - does not work with "date" as the filter

    I assume you are referring to the SaveAs Statement that is giving you the probelm. To use the Date there you would need to use the Format funtion, eg. Format(SaveDate, "mm/dd/yyyy") and concatenate it into the path string.
    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!

  5. #5
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    Re: Splitting Data to separate files - does not work with "date" as the filter

    Quote Originally Posted by JLGWhiz View Post
    I assume you are referring to the SaveAs Statement that is giving you the probelm. To use the Date there you would need to use the Format funtion, eg. Format(SaveDate, "mm/dd/yyyy") and concatenate it into the path string.
    I tried changing the Saveas statement to
    Please Login or Register  to view this content.
    And I get an error when i run the code.

    Ideally, I would like to keep this in VBA and not need extra formulas in the sheet if possible.

  6. #6
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    Re: Splitting Data to separate files - does not work with "date" as the filter

    Ideally I would like to just be able to have the file names saved as "Ship date 1", Ship date 2", etc... and not have the date in the file names whatsoever.

  7. #7
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    Re: Splitting Data to separate files - does not work with "date" as the filter

    Quote Originally Posted by alansidman View Post
    How about adding a column to your table and putting this formula in V5 and copying down then using column V to filter and split your data

    =IF(WEEKDAY([@ShipDate])=5,1,IF(WEEKDAY([@ShipDate])=6,2,IF(WEEKDAY([@ShipDate])=2,3,IF(WEEKDAY([@ShipDate])=3,4,5))))
    This coding works... ideally I would like it to be a behind the scenes done in VBA thing.. .but I can work with this!

    Thank you!

  8. #8
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    Re: Splitting Data to separate files - does not work with "date" as the filter

    Okay, so if I have a formula in the cell for the column that has the "=IF(WEEKDAY([@ShipDate])=5,1,IF(WEEKDAY([@ShipDate])=6,2,IF(WEEKDAY([@ShipDate])=2,3,IF(WEEKDAY([@ShipDate])=3,4,5))))" in it, then the macro will not run. If I convert the formula results to text, then the macro runs.

    So in the end, this is not working still.

    Any other thoughts for what I can try?

  9. #9
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,315

    Re: Splitting Data to separate files - does not work with "date" as the filter

    Possibly...
    Please Login or Register  to view this content.

  10. #10
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    Re: Splitting Data to separate files - does not work with "date" as the filter

    Quote Originally Posted by dangelor View Post
    Possibly...
    Please Login or Register  to view this content.
    Now that is perfect! One final question that I did not think of, and I will leave you alone.

    For the folder that it saves to, if I wanted to have it be "C:\Users\markf\Desktop\Test\Today's Date" so that each of the created files just went into a folder with the file creation date on it... would that be possible? Is it also possible to have a copy of the original file that the data is pulled from save in that folder as well? (that way if 1 year from now we had to reference the data we can easily find it and see the source data)

  11. #11
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    Re: Splitting Data to separate files - does not work with "date" as the filter

    I was able to figure out the creating a directory name + date... and KINDA SORTA have the saving of the original data file as well... but i think there is a better way to do the save. Please take a look at the below code and let me know your thoughts.



    Please Login or Register  to view this content.

  12. #12
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,315

    Re: Splitting Data to separate files - does not work with "date" as the filter

    As always, if it ain't broke, and it works, don't fix it. Could it be more 'elegant'? Probably... play with a copy and see what you can do and not do. Enjoy the day!

  13. #13
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    Re: Splitting Data to separate files - does not work with "date" as the filter

    Grrr.... Gotta love when things do not work exactly how you want them to.

    So I need to instead of having the files have a save name of a Date, the files need to save as literally the words "ShipDay1" "ShipDay2"... "ShipDay5"

    How do i pull that 1,2,3,4,5 into the "save as" info?

  14. #14
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,315

    Re: Splitting Data to separate files - does not work with "date" as the filter

    I incorporated Fluff13's formula... Not Tested!
    Please Login or Register  to view this content.

  15. #15
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    Re: Splitting Data to separate files - does not work with "date" as the filter

    Thank you for your help!

    One last thing that I just noticed

    I think that after the Autofilter 18 is put on that it needs to sort by that column?

    In looking at the files generated it showed "ShipDay5" as having the earliest ship date... Shipday1 had the second earliest....

    I think the code is pulling the date by the order in which a date appears in the column, not the order the date comes chronologically, if that makes sense

  16. #16
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,315

    Re: Splitting Data to separate files - does not work with "date" as the filter

    This tested OK on my system. The filename matched the shipdate day of the month - ShipDate2 = 8/2, ShipDate7 = 8/7, etc.
    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)

Similar Threads

  1. [SOLVED] Using data from workbook1 to "archive" into separate sheets (by date) in workbook2
    By jennis7242 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-18-2018, 02:06 AM
  2. Replies: 8
    Last Post: 06-21-2016, 08:56 AM
  3. Replies: 1
    Last Post: 01-22-2016, 09:21 AM
  4. Replies: 3
    Last Post: 01-02-2014, 02:15 PM
  5. Open files from FTP server (works with "servername" but doesn't work with "ip address")
    By adammsu1983 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-24-2012, 04:30 PM
  6. Advanced Filter "<=Date" does not work?
    By MAButler in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 04-04-2011, 05:08 PM
  7. [SOLVED] "Criteria Range" in the "Data/Filter/Advanced Filter" to select Du
    By TC in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-11-2005, 10:06 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