"Run Time error '9' - Subscript out of range"

clares

Well-known Member
Joined
Mar 14, 2002
Messages
557
Hi All

I am stepping through my code and I get to this line:

Set HelpSheet = ThisWorkbook.Sheets(HelpSheetName)

and it gives an error message:

"Run Time error 9 - Subscript out of range".

I have had a look at the help file, but dont really understand it.

Thanks in advance for any help

Kindest Regards
 

Some videos you may like

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Colo

MrExcel MVP,
Joined
Mar 20, 2002
Messages
1,456
Hi Peter,

Please re-confirm the variable HelpSheetName.
Does it have a value as string? :)
 

clares

Well-known Member
Joined
Mar 14, 2002
Messages
557
Option Explicit
Dim TopicCount As Integer
Dim CurrentTopic As Integer
Dim HelpSheet As Worksheet

Const AppName As String = "Clares Automated Pricing System"
Const HelpSheetName As String = "HelpSheet"
Const HelpFormCaption As String = AppName

String value.

Kind Regards
 

Colo

MrExcel MVP,
Joined
Mar 20, 2002
Messages
1,456
OK, OK. Your code works in my excel as follows.
...So, PLEASE check the name of the worksheet (HelpSheet),
if any space containd.
Eg,
(HelpSheet )
( HelpSheet)

Code:
Option Explicit
Dim TopicCount As Integer
Dim CurrentTopic As Integer
Dim HelpSheet As Worksheet

Const AppName As String = "Clares Automated Pricing System"
Const HelpSheetName As String = "HelpSheet"
Const HelpFormCaption As String = AppName

Sub test()
    Dim HelpSheet As Worksheet
    Set HelpSheet = ThisWorkbook.Sheets(HelpSheetName)
End Sub
 

clares

Well-known Member
Joined
Mar 14, 2002
Messages
557
Hi Colo

Thanks for that. I have checked my code with yours. But mine still brings the error up. I have checked and renamed the worksheet to ensure that there are no spaces in the name, either brgining and end!

Kindest Regards
 

bat17

Well-known Member
Joined
Aug 15, 2003
Messages
1,470
When you get to the line that bombs out have you checked that the value of HelpSheetName is still "HelpSheet" ?

Just wondering if somewhere esle in the code might be modifying it.

Peter
 

clares

Well-known Member
Joined
Mar 14, 2002
Messages
557
Hi there

When I glide my cursor over the row of code which is highlighted in yellow:

"Set HelpSheet = ThisWorkbook.Sheets(HelpSheetName)"

it display the following text

HelpSheet=Nothing,
ThisWorkbook.Sheets(HelpSheetName) <subscript out of range>
HelpSheetName = "HelpSheet"

Kindest Regards
 

clares

Well-known Member
Joined
Mar 14, 2002
Messages
557
Hi there

Sorry the previous should have read:

When I glide my cursor over the row of code which is highlighted in yellow:

"Set HelpSheet = ThisWorkbook.Sheets ( HelpSheetName )"

it display the following text

HelpSheet=Nothing,
ThisWorkbook.Sheets(HelpSheetName) <subscript out of range>
HelpSheetName = "HelpSheet"

Kindest Regards
 

clares

Well-known Member
Joined
Mar 14, 2002
Messages
557
Hi there

Sorry the previous should have read, ok this doesn;t like the less than or greater than brackets which subscript appears in:

When I glide my cursor over the row of code which is highlighted in yellow:

"Set HelpSheet = ThisWorkbook.Sheets ( HelpSheetName )"

it display the following text

HelpSheet=Nothing,
ThisWorkbook.Sheets(HelpSheetName) subscript out of range
HelpSheetName = "HelpSheet"

Kindest Regards
 

bat17

Well-known Member
Joined
Aug 15, 2003
Messages
1,470
I have just added colo's code to a new spreadsheet and it works fine for me. Can you post more of the code that you are actualy running?

Peter
 

Watch MrExcel Video

Forum statistics

Threads
1,102,134
Messages
5,484,932
Members
407,475
Latest member
Dix_Fix

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top