![]() |
out of range error for range value
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 |
out of range error for range value
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 |
out of range error for range value
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 |
out of range error for range value
Sorry, just ignore what I wrote as its not correct, an off moment!
James |
out of range error for range value
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 |
out of range error for range value
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 |
out of range error for range value
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 |
All times are GMT +1. The time now is 12:14 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com