Results 1 to 3 of 3

Thread: Setting filenames to incremental variables

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2013
    Posts
    17

    Setting filenames to incremental variables

    Hello!
    I have a folder with many files in it with the name format of RD130522 for the file made on may 22 2013.
    I have a code that I am using to move certain rows of data from one file to the previous file repetetively.
    for setting the file to which I want to move the rows to is there a way to save the file names to multiple variables such
    as assigning the 3rd and 4th character (13 in the example) to Y (for year) and 5th and 6th to M for month and 7th and 8th
    to D for day. So that I could move the data to filename ("RD" & Y & M & D-1) ? Does anyone know how to do this?

  2. #2

    Thread Starter
    Junior Member
    Join Date
    May 2013
    Posts
    17

    Re: Setting filenames to incremental variables

    or is there a way to automatically declare previous file for the file to move it to?

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Setting filenames to incremental variables

    try like
    Code:
    filen = "RD130522"
    prevfile = Left(filen, 2) & Format(DateSerial(Mid(filen, 3, 2), Mid(filen, 5, 2), Mid(filen, 7, 2) - 1), "yymmdd")
    Debug.Print prevfile
    change format if required
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width