![]() |
Range only works when Sheet Name is "Sheet1"
Hi,
I have a single worksheet spreadsheet whose properties show the value of the "(Name)" to be "Sheet1"...however the "Name" property is "financial". When I do this: Worksheets("Sheet1").Range("A6:O106") I get a subscript error. If I do this: Worksheets("financial").Range("A6:O106") I also get subscript error. ....however...whenever I change the "Name" property to be "Sheet1" instead of "financial" and do this: Worksheets("Sheet1").Range("A6:O106") I get access to the range I want and all is well. ....any ideas. Thanks |
Range only works when Sheet Name is "Sheet1"
Paul,
When you say the name property, what exactly are you referring to? Did you change the (Name) at the top of the properties window? If so, this is the codename of the sheet, and you use this like so financials.Range("A6:O106") You can double check this by seeing if the worksheet tab name changes, if not it is the codename. -- HTH Bob Phillips "paul reed" wrote in message ... Hi, I have a single worksheet spreadsheet whose properties show the value of the "(Name)" to be "Sheet1"...however the "Name" property is "financial". When I do this: Worksheets("Sheet1").Range("A6:O106") I get a subscript error. If I do this: Worksheets("financial").Range("A6:O106") I also get subscript error. ...however...whenever I change the "Name" property to be "Sheet1" instead of "financial" and do this: Worksheets("Sheet1").Range("A6:O106") I get access to the range I want and all is well. ...any ideas. Thanks |
Range only works when Sheet Name is "Sheet1"
Just to clarify what Bob is saying:
Since you said your code name [ (Name) ] property is Sheet1 then usage would be Sheet1.Range("A6:A106") If you get a subscript out of range when you do Worksheets("financial").Range("A6:A106") then the name "financial" does not match the tab name. Whatever the difference was in your first test, when you retyped it to Sheet1 and then used Worksheets("Sheet1").Range("A6:A106") you then matched the argument to a Worksheet with an existing worksheet name (the worksheet name has nothing to do with the codename - just when the sheets are created, the sheetname and codename will match for the English version of Excel at least). When you look at properties, the is a property Name without the parentheses - this is the name you see on the tab and the argument to the Worksheets collection. I suspect when the sheet was named financial, it had a space at the end which caused the mismatch. Try renaming the sheet to financial and reference you range again using Worksheets("financial").Range("A6:A106"). Also, the name is not case sensitive. -- Regards, Tom Ogilvy Bob Phillips wrote in message ... Paul, When you say the name property, what exactly are you referring to? Did you change the (Name) at the top of the properties window? If so, this is the codename of the sheet, and you use this like so financials.Range("A6:O106") You can double check this by seeing if the worksheet tab name changes, if not it is the codename. -- HTH Bob Phillips "paul reed" wrote in message ... Hi, I have a single worksheet spreadsheet whose properties show the value of the "(Name)" to be "Sheet1"...however the "Name" property is "financial". When I do this: Worksheets("Sheet1").Range("A6:O106") I get a subscript error. If I do this: Worksheets("financial").Range("A6:O106") I also get subscript error. ...however...whenever I change the "Name" property to be "Sheet1" instead of "financial" and do this: Worksheets("Sheet1").Range("A6:O106") I get access to the range I want and all is well. ...any ideas. Thanks |
Range only works when Sheet Name is "Sheet1"
That could be a problem if the macro isn't working against the activesheet. But
if it is, why not just: activesheet.range(...) Ed Lisay wrote: A better way of doing this is avaid hardcoding the sheet name. That way, even if the User changes the sheet name the code will still run. Example: 'get the sheet name mySheetName = ActiveCell.Worksheet.Name 'pass the name to your code Worksheets(mySheetName).Range("A6:O106") <<snipped -- Dave Peterson |
All times are GMT +1. The time now is 01:41 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com