ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run time error 9 (Subscript Out Of Range) (https://www.excelbanter.com/excel-programming/410852-run-time-error-9-subscript-out-range.html)

Heera

Run time error 9 (Subscript Out Of Range)
 
Hi,

I am getting a error.

Run time error 9 on this line of code ( Windows(hirename).Activate ) I
am not able to understand it i also tried alternative code
wookbooks("Hrining Plan.xls").Activate but it is also not working.

Sub RamPlan()

Workbooks("Ramp Plan Macro.xls").Activate
Sheets("Macro").Select

Dim hirePath As String
Dim ramppath As String
Dim hirename As String
Dim rampName As String

hirePath = Range("c8").Value
ramppath = Range("c9").Value
hirename = Range("c10").Value
rampName = Range("c11").Value


Workbooks.Open ramppath & "\" & rampName
Workbooks.Open hirePath & "\" & hirename

Workbooks("Ramp Plan Macro.xls").Activate
Sheets("Macro").Select

Dim fromdate As Variant
fromdate = Range("c13").Value

Windows(hirename).Activate
Sheets("C LLC").Select
Range("A2").Select

Do Until Selection.Value = fromdate
Selection.Offset(1, 0).Select
Loop
Selection.Offset(0, 5).Select

End Sub

Jon Peltier

Run time error 9 (Subscript Out Of Range)
 
Assume typos in 'wookbooks("Hrining Plan.xls")' were created for our
benefit. Is hirename a hidden workbook? Is it an add-in?

You can skip all the activating and deactivating:

Workbooks.Open ramppath & "\" & rampName
Workbooks.Open hirePath & "\" & hirename

Dim fromdate As Variant
fromdate = Workbooks("Ramp Plan
Macro.xls").Sheets("Macro").Range("c13").Value
' note: Worksheets is better in most cases than Sheets (IntelliSense,
etc.)

Dim myCell As Range
Set myCell = Windows(hirename).Sheets("C LLC").Range("A2")
Do Until myCell.Value = fromdate
Set myCell = myCell.Offset(1, 0)
Loop
Set myCell = myCell.Offset(0, 5)


- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______



"Heera" wrote in message
...
Hi,

I am getting a error.

Run time error 9 on this line of code ( Windows(hirename).Activate ) I
am not able to understand it i also tried alternative code
wookbooks("Hrining Plan.xls").Activate but it is also not working.

Sub RamPlan()

Workbooks("Ramp Plan Macro.xls").Activate
Sheets("Macro").Select

Dim hirePath As String
Dim ramppath As String
Dim hirename As String
Dim rampName As String

hirePath = Range("c8").Value
ramppath = Range("c9").Value
hirename = Range("c10").Value
rampName = Range("c11").Value


Workbooks.Open ramppath & "\" & rampName
Workbooks.Open hirePath & "\" & hirename

Workbooks("Ramp Plan Macro.xls").Activate
Sheets("Macro").Select

Dim fromdate As Variant
fromdate = Range("c13").Value

Windows(hirename).Activate
Sheets("C LLC").Select
Range("A2").Select

Do Until Selection.Value = fromdate
Selection.Offset(1, 0).Select
Loop
Selection.Offset(0, 5).Select

End Sub




T Lavedas

Run time error 9 (Subscript Out Of Range)
 
On May 13, 8:31 am, Heera wrote:
Hi,

I am getting a error.

Run time error 9 on this line of code ( Windows(hirename).Activate ) I
am not able to understand it i also tried alternative code
wookbooks("Hrining Plan.xls").Activate but it is also not working.

Sub RamPlan()

Workbooks("Ramp Plan Macro.xls").Activate
Sheets("Macro").Select

Dim hirePath As String
Dim ramppath As String
Dim hirename As String
Dim rampName As String

hirePath = Range("c8").Value
ramppath = Range("c9").Value
hirename = Range("c10").Value
rampName = Range("c11").Value

Workbooks.Open ramppath & "\" & rampName
Workbooks.Open hirePath & "\" & hirename

Workbooks("Ramp Plan Macro.xls").Activate
Sheets("Macro").Select

Dim fromdate As Variant
fromdate = Range("c13").Value

Windows(hirename).Activate
Sheets("C LLC").Select
Range("A2").Select

Do Until Selection.Value = fromdate
Selection.Offset(1, 0).Select
Loop
Selection.Offset(0, 5).Select

End Sub


There is not really enough information to be certain what your problem
is, but it appears that the Window named by the contents of the cell
C10 referenced does not match the Caption property of any of the
opened workbook windows.

What exactly are you trying to accomplish?

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Heera

Run time error 9 (Subscript Out Of Range)
 
thank you Jon...it is working fine.

Jon Peltier

Run time error 9 (Subscript Out Of Range)
 
Post on top like everyone else, to make it easier to read.

There is not really enough information to be certain what your problem
is, but it appears that the Window named by the contents of the cell
C10 referenced does not match the Caption property of any of the
opened workbook windows.


But the OP didn't mention a problem with this line:

Workbooks.Open hirePath & "\" & hirename

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"T Lavedas" wrote in message
...
On May 13, 8:31 am, Heera wrote:
Hi,

I am getting a error.

Run time error 9 on this line of code ( Windows(hirename).Activate ) I
am not able to understand it i also tried alternative code
wookbooks("Hrining Plan.xls").Activate but it is also not working.

Sub RamPlan()

Workbooks("Ramp Plan Macro.xls").Activate
Sheets("Macro").Select

Dim hirePath As String
Dim ramppath As String
Dim hirename As String
Dim rampName As String

hirePath = Range("c8").Value
ramppath = Range("c9").Value
hirename = Range("c10").Value
rampName = Range("c11").Value

Workbooks.Open ramppath & "\" & rampName
Workbooks.Open hirePath & "\" & hirename

Workbooks("Ramp Plan Macro.xls").Activate
Sheets("Macro").Select

Dim fromdate As Variant
fromdate = Range("c13").Value

Windows(hirename).Activate
Sheets("C LLC").Select
Range("A2").Select

Do Until Selection.Value = fromdate
Selection.Offset(1, 0).Select
Loop
Selection.Offset(0, 5).Select

End Sub


There is not really enough information to be certain what your problem
is, but it appears that the Window named by the contents of the cell
C10 referenced does not match the Caption property of any of the
opened workbook windows.

What exactly are you trying to accomplish?

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/





All times are GMT +1. The time now is 08:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com