PDA

View Full Version : VBA code error



bopha99
02-04-2014, 06:30 PM
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

Aussiebear
02-04-2014, 06:59 PM
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

Paul_Hossler
02-04-2014, 07:32 PM
what happens if you replace the%20 with a space?



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


Paul

Aflatoon
02-05-2014, 03:43 AM
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.