Consulting

Results 1 to 4 of 4

Thread: VBA code error

  1. #1
    VBAX Regular
    Joined
    Mar 2013
    Posts
    51
    Location

    VBA code error

    I have a code below where when I run it gives me a Runtime error 9 sub script out of range error. The code works, but it still gives me that error. Does that mean the VBA code cannot locate the csv file mentioned on the debug row? Thanks in advance.

    Sub Price()
    'Price Macro
    Columns("C:E").Select
        Selection.Delete Shift:=xlToLeft
        Range("A1").Select
        ActiveCell.FormulaR1C1 = "Ticker"
        Range("B1").Select
        ActiveCell.FormulaR1C1 = "CustomTradePrice"
        Columns("B:B").Select
        Windows("mBOSExport%20OCM%20Daily%20Prices%20##20110706.csv").Activate    <= debug problem
        Windows("Prices.csv").Activate
        Range("C1").Select
    End Sub
    Last edited by Aussiebear; 02-04-2014 at 06:55 PM. Reason: enclosed code within tags

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,050
    Location
    While this doesn't get to your main issue, this a better way to start the code
    Columns("C:E").Delete Shift:=xlToLeft 
    Range("A1").value = "Ticker" 
    Range("B1").Value = "CustomTradePrice" 
    Columns("B:B").Select 
    Windows("mBOSExport%20OCM%20Daily%20Prices%20##20110706.csv").Activate    <= debug problem 
    Windows("Prices.csv").Activate 
    Range("C1").Select
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    what happens if you replace the%20 with a space?

    Windows("mBOSExport OCM Daily Prices ##20110706.csv").Activate    <= debug problem
    Paul

  4. #4
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    I suggest you use Workbooks rather than Windows. If you have explorer set to hide file extensions, that will affect whether you should include the extension if you use Windows in your code, but not if you use Workbooks.
    Be as you wish to seem

Posting Permissions

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