Consulting

Results 1 to 3 of 3

Thread: Overflow Error when using Format()

  1. #1
    VBAX Regular
    Joined
    Jul 2019
    Posts
    51
    Location

    Overflow Error when using Format()

    I'm getting an Overflow error when trying to insert the date into the new file I have VBA creating when a user clicks a button.

    Public Sub GenerateAuditFile()
        Application.ScreenUpdating = False
        
        Dim ActiveRow As Integer: ActiveRow = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row
        Dim SOPID As Variant
        With ActiveSheet
            'Set SOPID to variable
            SOPID = .Cells(ActiveRow, 1)
        End With
        
        'Built new audit filename
        Dim NewAuditFileName As String: NewAuditFileName = "SOP_Audit-JV-" & Format(SOPID, "000") & "-" & Format(Now, "MMddyyyy") & ".xlsx"
        
        'If it doesn't already exist, copy and rename the SOP audit file
        If Dir("\\JACKSONVILLE-DC\Common\SOP's for JV\SOP Audits\" & NewAuditFileName) <> "" Then
            MsgBox ("File: " & NewAuditFileName & " exists")
        Else
            'Create new audit file
            FileCopy "\\JACKSONVILLE-DC\Common\SOP's for JV\SOP Audits\SOP Audit Checklist-Template.xlsx", _
                     "\\JACKSONVILLE-DC\Common\SOP's for JV\SOP Audits\2019\" & NewAuditFileName
                     
            With ActiveSheet
                Dim wbNewAudit As Workbook: Set wbNewAudit = Workbooks.Open("\\JACKSONVILLE-DC\Common\SOP's for JV\SOP Audits\2019\" & NewAuditFileName)
                'wbNewAudit.Windows(1).Visible = False
                'MsgBox (ActiveSheet.Cells(ActiveRow, 3))
            
                wbNewAudit.Worksheets(1).Range("A1") = "SOP Title: " & .Cells(ActiveRow, 3)
                wbNewAudit.Worksheets(1).Range("F1") = "Date: " & Format(Now, “MM / dd / yyyy”)
            End With
        End If
        
        Application.ScreenUpdating = True
        
        'TEST - Output SOPID
        'MsgBox (Format(SOPID, "000"))
    End Sub
    The field it is being sent to is a "General" field type.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    IF that is an accurate copy/paste, then in

     Format(Now, “MM / dd / yyyy”)
    you have 'curly quotes', not the required regular-old VBA quote (ASCII 34)

    Your Format might have been pasted from a web site or something

    Otherwise it works


    Capture.JPG

    BTW, you had at least 3 Format statements in there. It'd be helpful to let us know which one threw the error
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular
    Joined
    Jul 2019
    Posts
    51
    Location
    It must have been when I copy/pasted as you suggested. It's solved now. Thank you!

Tags for this Thread

Posting Permissions

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