Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi;
i'm trying to capture a value in a range. I have the following codeattched to the click action on a button in my "Results" sheet: Dim LastDataRow As Integer LastDataRow = Worksheets("Data").Range("E1").Value When the above line is reached, I get a "Run time error '9' Subscript out of range" error message. Cell E1 of the worksheet labelled "Data" has the value 9 in it. I tried displaying the value of it by the line : MsgBox Worksheets("Data").Range("E1").Value which was placed just before the problem line. When the MsgBox line executed, the value was blank in the message box. I'm at a loss as to what the problem is. Any help is greatly appreciated. -- JJFJR |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
Yeah just change Worksheets to Sheets. Different Collections so its not registering what you are trying to do. Any Problems then give me a shout. James |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi JJFJR,
The "Subscript out of range" message indicates a failure to find a worksheet named 'Data'. Check that there are no spaces at the beginning or end of the sheet's name. --- Regards, Norman "jjfjr" wrote in message ... Hi; i'm trying to capture a value in a range. I have the following codeattched to the click action on a button in my "Results" sheet: Dim LastDataRow As Integer LastDataRow = Worksheets("Data").Range("E1").Value When the above line is reached, I get a "Run time error '9' Subscript out of range" error message. Cell E1 of the worksheet labelled "Data" has the value 9 in it. I tried displaying the value of it by the line : MsgBox Worksheets("Data").Range("E1").Value which was placed just before the problem line. When the MsgBox line executed, the value was blank in the message box. I'm at a loss as to what the problem is. Any help is greatly appreciated. -- JJFJR |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sorry, just ignore what I wrote as its not correct, an off moment!
James |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Interesting to note however that the OP tested with Msgbox
Worksheets("Data").Range("E1").value and did NOT get the same error message .... which they should have if the problem is the worksheet name. I will be interested to see what they respond to this! Bill "Norman Jones" wrote in message ... Hi JJFJR, The "Subscript out of range" message indicates a failure to find a worksheet named 'Data'. Check that there are no spaces at the beginning or end of the sheet's name. --- Regards, Norman "jjfjr" wrote in message ... Hi; i'm trying to capture a value in a range. I have the following codeattched to the click action on a button in my "Results" sheet: Dim LastDataRow As Integer LastDataRow = Worksheets("Data").Range("E1").Value When the above line is reached, I get a "Run time error '9' Subscript out of range" error message. Cell E1 of the worksheet labelled "Data" has the value 9 in it. I tried displaying the value of it by the line : MsgBox Worksheets("Data").Range("E1").Value which was placed just before the problem line. When the MsgBox line executed, the value was blank in the message box. I'm at a loss as to what the problem is. Any help is greatly appreciated. -- JJFJR |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi William,
Good point. I might assume that the sheet name had been spelled correctly in one line and wrongly in the other, but that would not explain the empty value returned by the Msgbox. --- Regards, Norman "William Benson" wrote in message ... Interesting to note however that the OP tested with Msgbox Worksheets("Data").Range("E1").value and did NOT get the same error message ... which they should have if the problem is the worksheet name. I will be interested to see what they respond to this! Bill "Norman Jones" wrote in message ... Hi JJFJR, The "Subscript out of range" message indicates a failure to find a worksheet named 'Data'. Check that there are no spaces at the beginning or end of the sheet's name. --- Regards, Norman |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Also, while I do not have enough info to answer your stated problem, I will
caution against using integer type variables to hold row numbers except under VERY controlled circumstances. INTEGER: -32,768 to 32,767 [Note: Rows can go to 65,536!] LONG: -2,147,483,648 to 2,147,483,647 "jjfjr" wrote in message ... Hi; i'm trying to capture a value in a range. I have the following codeattched to the click action on a button in my "Results" sheet: Dim LastDataRow As Integer LastDataRow = Worksheets("Data").Range("E1").Value When the above line is reached, I get a "Run time error '9' Subscript out of range" error message. Cell E1 of the worksheet labelled "Data" has the value 9 in it. I tried displaying the value of it by the line : MsgBox Worksheets("Data").Range("E1").Value which was placed just before the problem line. When the MsgBox line executed, the value was blank in the message box. I'm at a loss as to what the problem is. Any help is greatly appreciated. -- JJFJR |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I enter formula sum(range+range)*0.15 sumif(range=3) | Excel Discussion (Misc queries) | |||
Excel Addin:Setting the range to the Excel.Range object range prop | Excel Worksheet Functions | |||
Type Mismatch error & subscript out of range error | Excel Programming | |||
Range Question / error 1004: method Range of object Worksheet has failed | Excel Programming | |||
Adding named range gives error "method range of object _Global failed " | Excel Programming |