Consulting

Results 1 to 3 of 3

Thread: Subscript out of range

  1. #1

    Subscript out of range

    I am trying to "Save As" twice for a file but with a different name. However, I am having some issues issues with the last name of the code below. Please note, I left off some irrelevant codes from the program as I did not want to confuse anyone with unnecessary information

    Sub credit_monitor()
    
    Dim FileName1 As String
    Dim LR As Long
    Dim TaxRate As String
    Dim SumAllCountries As Variant
    Dim LR2 As Variant
    Dim LR3 As Variant
    Dim xdate As String
    Dim fname As Variant
    Dim fname2 As Variant
    
    FileName1 = Workbooks("Macros").Sheets(1).Cells(7, 2)
            Workbooks(FileName1).Activate
    Workbooks(FileName1).Sheets(1).Select
    
    xdate = Cells(8, 2)
    FR = Range("A" & Rows.Count).End(xlUp)
            xdate = Workbooks("Macros").Sheets(1).Cells(8, 2)
        pth = "S:\Stock Loan\Clients\Vanguard\Reporting\Credit Monitor\"
    fname = pth & "Trades as of" & " " & xdate & " " & "BBH The Chase" & ".xlsx"
    Debug.Print fname
    
    Workbooks(FileName1).SaveAs FileName:=fname, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
    
    Range("A1:Q1").AutoFilter
    Columns(1).Delete
    Columns(2).Delete
    
    fname2 = pth & "Trades as of" & " " & xdate & " " & "Vanguard" & ".xlsx"
    Debug.Print fname2
    
    Workbooks(fname).SaveAs FileName:=fname2, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False



    ^ That last line has an error and spits out the "Subscript out of range" message. I would greatly appreciate any help!
    Last edited by SamT; 08-11-2017 at 12:39 PM.

  2. #2
    Apologies for the thread. Problem was solved. I just made a slight error towards the end in using invalid characters.

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You could also use SaveCopyAs
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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