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

clares

Well-known Member
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
 

Colo

MrExcel MVP,
Hi Peter,

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

clares

Well-known Member
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,
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
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
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
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
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
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
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
 

Some videos you may like

This Week's Hot Topics

  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • find many based on a certain criteria
    good evening, I hope someone can help me? I have a workbook sheet 2 contains lots of data.... I would like to be able to find anything on sheet...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
  • Text Format
    I have a sheet for user to keyin the data. The format of the data can be 451 / 1903, 0012 / 9908 or 00287 / 0099. The number after the "/" is...
  • Syntax errors
    Good Morning, Trying to compile a workbook, I keep getting a few errors. Here are the first two: [code=rich]Syntax Error: Function...
Top