Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: How to Save a Date into the Filename of a spreadhseet?

  1. #11
    New Member
    Join Date
    Mar 2002
    Posts
    33
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hey Guys, THANK YOU very much for all your help. Your code(s) worked perfectly and I'm up and running (for now!)

    Thanks,

    Rob

  2. #12
    New Member
    Join Date
    Mar 2002
    Posts
    33
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-03-18 14:57, NateO wrote:
    Howdy. I changed the code in my earlier post
    Code:
    Sub LastSat3()
    Dim nth As Variant
    nth = [c3].Value
    If IsDate(nth) Then
    nth = Format(nth, "yyyymmdd")
    Else: MsgBox ("Invalid Date" & Chr(13) & Chr(13) & "Check cell C3")
    Exit Sub
    End If
    ThisWorkbook.SaveAs Filename:="Reg_01_" & nth
    End Sub
    Hey Guys,

    One last question on this same topic. I am working on a slight variation of the code that was given in the quote above. What I would like it to do is take the month in the variant for "nth" (nth = Format(nth, "yyyymmdd")) and automatically add one month to the date.. so if the date it references says February 28, 2002, I want the filename date to return as "200203" since by our definitions, this report would be a "march" report. Confusing I know, but any help here would be appreciated.

    Thanks,

    Rob

  3. #13
    MrExcel MVP Al Chara's Avatar
    Join Date
    Feb 2002
    Location
    Newark, Delaware
    Posts
    1,701
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Try the following code:

    Dim nth As Variant
    nth = [c3].Value
    If IsDate(nth) Then
    nth = Format(nth, "yyyymm")
    Else: MsgBox ("Invalid Date" & Chr(13) & Chr(13) & "Check cell C3")
    Exit Sub
    End If
    If nth = 200212 Then
    nth = 200301
    Else: nth = nth + 1
    End If
    ThisWorkbook.SaveAs Filename:="Reg_01_" & nth

    Its not the greatest code but it will work for every month in 2002.
    Best regards,
    Allan Chara
    http://www.mrspreadsheets.com

  4. #14
    New Member
    Join Date
    Mar 2002
    Posts
    33
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-03-20 10:14, Al Chara wrote:
    Try the following code:

    Dim nth As Variant
    nth = [c3].Value
    If IsDate(nth) Then
    nth = Format(nth, "yyyymm")
    Else: MsgBox ("Invalid Date" & Chr(13) & Chr(13) & "Check cell C3")
    Exit Sub
    End If
    If nth = 200212 Then
    nth = 200301
    Else: nth = nth + 1
    End If
    ThisWorkbook.SaveAs Filename:="Reg_01_" & nth

    Its not the greatest code but it will work for every month in 2002.
    Wonderful!

    That worked! Another thing I did, just by messing around was to change the "nth = [c3].Value" to "nth = [c3].Value + 2" Trial and error I suppose, but what that appeared to do was add 2 days to the date referenced in cell C3.. so the date in C3 was "February 28, 2002"... and by adding 2 it became "March 2, 2002"... and hence the filename reflected the month of that date.

    Does that seem like a logical way to do it? or could I be running into more problems? Anyways, thanks so much for your help.

    Rob

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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