Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default 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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Range only works when Sheet Name is "Sheet1"

When you're in the VBE and looking at the project explorer, you see something
like:

VBAProject (book1.xls)
Microsoft Excel Objects
Sheet1 (Financial)
or do you see
Financial (Sheet1)

Each worksheet has a .name property (that you can see on the worksheet tab in
Excel). It's the name in parentheses in the project explorer.

And each worksheet has a .codename property. It's the "name" not in
parentheses.

If you click on that item in the project explorer and hit F4 so you can view the
properties, you'll see the top entry (in the alphabetic tab) is (Name). That
represents the .codename.

A little lower in the list is the worksheet name.

======
Now my point <bg.

If you spelled one of those examples correctly, it should work.

You can refer to a worksheet like:
worksheets("mySheetName").range(....)
(mysheetname is the name you can see on the worksheet's tab in excel.)

But if your user renames the sheet, then this code breaks.

If the code name were Sheet1, you could also refer to that sheet as:
sheet1.range(...)

Most users don't know how to change this name, so it's a lot safer.

In your case, I'd check the spelling (and maybe look for leading/trailing
spaces).


paul reed wrote:

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


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Active sheet instead of a "sheet1" for Macro Pantera Excel Worksheet Functions 7 December 31st 08 07:47 PM
how do i convert this to a formula +"sheet1!J"&(sheet2!A30)-1 joel Excel Worksheet Functions 3 December 5th 07 01:48 PM
how do copy "sheet1!A1+1 in sheet2 to sheet 3 and get "sheet2!A1+ Dany Excel Discussion (Misc queries) 5 April 16th 07 03:27 AM
Help required with setting up a pivot table with the source on sheet1 to have the pivot table created on sheet called "report" Diana[_5_] Excel Programming 0 August 21st 03 10:19 PM
Sheet1 object not Worksheets("Sheet1") onedaywhen Excel Programming 2 August 12th 03 12:38 PM


All times are GMT +1. The time now is 11:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"