+ Reply to Thread
Results 1 to 17 of 17

Use Date In File Name to Enter Date in Cell

  1. #1
    Forum Contributor
    Join Date
    09-19-2003
    Posts
    226

    Red face Use Date In File Name to Enter Date in Cell

    Hi Y'all

    Someone said that this can't be done! I said that he does not know what the guys and girls on the Excel Forum can do with Excel.
    I have a file that is a template. Each day I need to save the template as the following file: "Summary of Shop Daily Charges- 16 October 2016.xls", the next day, "Summary of Shop Daily Charges- 17 October 2016.xls", etc.
    In the file there is a cell where the date needs to be entered. I can be a bit scatterbrain sometimes and forget to change the date. So, can you help me build a Macro that when I rename and save the file with the new date that the Macro will pick up the date and enter it into the Cell?

    Please prove that person wrong!!!!!

    Many thanks

    Patish
    Attached Files Attached Files
    Patish

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Use Date In File Name to Enter Date in Cell

    Put this in the WORKBOOK module:
    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Valued Forum Contributor
    Join Date
    05-08-2015
    Location
    Uvalde, TX
    MS-Off Ver
    2010
    Posts
    720

    Re: Use Date In File Name to Enter Date in Cell

    Hi,

    I think you are looking at this the wrong way. Instead of having the macro change the date in the cell the match the date of the file name, you have it save the file name to include the date in the cell.

    You can put this formula in cell C2 which will automatically reflect the current day:
    Please Login or Register  to view this content.
    I am terrible with macro's but have seen them used to save file names using data from a cell.

    Hope this is helpful.

    Cheers

  4. #4
    Forum Contributor
    Join Date
    09-19-2003
    Posts
    226

    Re: Use Date In File Name to Enter Date in Cell

    Quote Originally Posted by Olly View Post
    Put this in the WORKBOOK module:
    Please Login or Register  to view this content.
    Hi Olly

    Thanks for the code, but this is a bit above what I am used to doing. I do not save the file by using a Macro. What I normally do with the template file is to Save As, find the file with the last date, click on the name, change the date from 16 to 17, let say, and hit Save. How would I put that into Code and add the the code that you built?

    Thanks

    Patish

  5. #5
    Forum Contributor
    Join Date
    09-19-2003
    Posts
    226

    Re: Use Date In File Name to Enter Date in Cell

    Hi Olly

    Could not quite make heads or tails of how to adapt your macro to my spreadsheet.. I have attached the file with the Macro according to what I think it should be. Horribly wrong because it does not work. Can you help me please?

    Also, is it important what the date format should be in this Macro? For example, dd/mmm/yyyy, dd mmmm yyyy, and so on?

    Thanks

    Patish

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Use Date In File Name to Enter Date in Cell

    Does this help?

    Please Login or Register  to view this content.
    y = the total number of characters in the workbook name - 31 (31 represents the number of characters up to where the date begins.

    y-4 where (4 represents .xls) last 4 characters

    x should give you any date you place there in the workbook name.

  7. #7
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Use Date In File Name to Enter Date in Cell

    If you want a non-VBA solution, you can use the =CELL() function to return the filename https://support.office.com/en-us/art...f-955d67c2b2cf Then using the different text functions [=MID() ], you can pull out the date information from the resulting text string.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Use Date In File Name to Enter Date in Cell

    Yet another:

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    09-19-2003
    Posts
    226

    Re: Use Date In File Name to Enter Date in Cell

    Many thanks, John. Your second solution was a success. Did not understand why the first one had a message box. Am I correct in saying that the date placed in the cell is text? Any way it can be changed to a value in the Macro?

    Thanks

    Brian

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Use Date In File Name to Enter Date in Cell

    You're welcome. Glad to help out. Try:

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    09-19-2003
    Posts
    226

    Re: Use Date In File Name to Enter Date in Cell

    John

    That clinched it. Works like a well tuned engine. Many thanks.

    I hope the elections on November 8 goes just as well!!!!!

    Patish

  12. #12
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Use Date In File Name to Enter Date in Cell

    You're welcome. Thanks for the feedback and the reps.

  13. #13
    Registered User
    Join Date
    10-22-2016
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    19

    Re: Use Date In File Name to Enter Date in Cell

    Quote Originally Posted by JOHN H. DAVIS View Post
    You're welcome. Glad to help out. Try:

    Please Login or Register  to view this content.
    Hi

    I was interested in using this code as well. It fits exactly for purposes at work. However I get a run-time errror 1004: application-defined object or object-defined error and when i click Debug, the line highlighted is
    Please Login or Register  to view this content.

  14. #14
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Use Date In File Name to Enter Date in Cell

    See link below for Forum Rules. Refer too Rule No. 2.

    http://www.excelforum.com/forum-rule...rum-rules.html

    If you start a thread then I will be glad to help you.

  15. #15
    Registered User
    Join Date
    10-22-2016
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    19

    Re: Use Date In File Name to Enter Date in Cell

    Sorry about that. I have created a thread here http://www.excelforum.com/showthread.php?t=1161252

    Much appreciated

  16. #16
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Use Date In File Name to Enter Date in Cell

    I just posted in your new thread.

  17. #17
    Forum Contributor
    Join Date
    09-19-2003
    Posts
    226

    Re: Use Date In File Name to Enter Date in Cell

    Hi JOHN H.

    Can you help me please? Your code works beautifully when the date in the file name is 25 June 2018.

    I have changed the date that appears in my file name to 25062018 and, using your code there is an error. It points to the last line

    .value= .value.

    Is there code that can take into account any changes in date formats in a file name? Or is there a rule that I can use if I need to change the date format?

    Many thanks

    Patish

+ 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. Prompt user to enter date, then validate date, then continue with macro
    By rgiglio7489 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-18-2014, 04:54 PM
  2. [SOLVED] Prefill text box in userform with today's date but allow user to enter unique date
    By moosetales in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-02-2014, 09:17 AM
  3. VBA to enter date range based on date range in above cell
    By Pierce Quality in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-19-2013, 08:45 AM
  4. Replies: 4
    Last Post: 05-01-2013, 07:38 PM
  5. Replies: 1
    Last Post: 10-02-2012, 02:42 PM
  6. Replies: 3
    Last Post: 08-18-2010, 12:58 PM
  7. [SOLVED] Excel: I enter date and format for date, but shows as number
    By spohar in forum Excel General
    Replies: 2
    Last Post: 03-10-2006, 04:45 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