Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default range name define on non active(focused) sheet

VBA Code range name define on other sheet

I use more than one sheet,
the focus is on sheet1
how I can , define a range name (with Names object let say) on sheet2
while the focus ,means active screen, is on sheet1.

I got an error that the application object of range name (in sheet2)
is not defined...
if I make active sheet as sheet2 , it works correctly

any help will be appreciated

EL


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default range name define on non active(focused) sheet

As always, you should post your code for comments.

Try something like this:

ThisWorkbook.Names.Add Name:="TestRng",
RefersTo:=Worksheets("Sheet2").Range("A1")

Regards,
Per

On 21 Jan., 10:50, ell wrote:
VBA Code range name define on other sheet

I use more than one sheet,
the focus is on sheet1
how I can , define a range name (with Names object let say) on sheet2
while the focus ,means active screen, is on sheet1.

I got an error that the application object of range name (in sheet2)
is not defined...
if I make active sheet as sheet2 , it works correctly

any help will be appreciated

EL


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 168
Default range name define on non active(focused) sheet

On Jan 21, 4:29*am, Per Jessen wrote:
As always, you should post your code for comments.

Try something like this:

ThisWorkbook.Names.Add Name:="TestRng",
RefersTo:=Worksheets("Sheet2").Range("A1")

Regards,
Per

On 21 Jan., 10:50, ell wrote:



VBA Code range name define on other sheet


I use more than one sheet,
the focus is on sheet1
how I can , define a range name (with Names object let say) on sheet2
while the focus ,means active screen, is on sheet1.


I got an error that the application object of range name (in sheet2)
is not defined...
if I make active sheet as sheet2 , it works correctly


any help will be appreciated


EL- Hide quoted text -


- Show quoted text -


Or,
sheets("sheet2").range("a1").name="Don"
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default range name define on non active(focused) sheet

On Jan 21, 3:55*pm, Don Guillett Excel MVP
wrote:
On Jan 21, 4:29*am, Per Jessen wrote:









As always, you should post your code for comments.


Try something like this:


ThisWorkbook.Names.Add Name:="TestRng",
RefersTo:=Worksheets("Sheet2").Range("A1")


Regards,
Per


On 21 Jan., 10:50, ell wrote:


VBA Code range name define on other sheet


I use more than one sheet,
the focus is on sheet1
how I can , define a range name (with Names object let say) on sheet2
while the focus ,means active screen, is on sheet1.


I got an error that the application object of range name (in sheet2)
is not defined...
if I make active sheet as sheet2 , it works correctly


any help will be appreciated


EL- Hide quoted text -


- Show quoted text -


Or,
sheets("sheet2").range("a1").name="Don"

Hi Julliet
the code:
sheets("sheet2").range("a1").name="Don"
is working correctly if I start from sheet2 (from command button on
sheet2 let say)
but from command button in sheet1 ,where the active sheet is sheet1,
from my tests, I noticed
error message on object application...
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default range name define on non active(focused) sheet

ell brought next idea :
Hi Julliet
the code:
sheets("sheet2").range("a1").name="Don"
is working correctly if I start from sheet2 (from command button on
sheet2 let say)
but from command button in sheet1 ,where the active sheet is sheet1,
from my tests, I noticed
error message on object application...


First thing I'll say here is that unless there's a specific reason to
create global names (ie: workbook level) all defined names should be
made local (ie: sheet level). This removes any/all ambiguity about
defined names withing a workbook. It also allows using duplicate names
on other sheets withing the same workbook.

If you open the defined name dialog while Sheet2 is active, you will
not see the sheetname to the right in the list. If the sheetname isn't
listed to the right then any name missing that are global (workbook
level) So.., to achieve this with naming 'A1' on 'Sheet2' it should
be...

Sheets("Sheet2").Range("A1").Name = "'Sheet2'!Don"

**Note that the sheetname is wrapped in apostrophes followed by the
exclamation character. So the syntax for defining local names is...

'sheet name'!DefinedName


Now when you open the defined name dialog you'll see 'Sheet2' to the
right of 'Don' in the list. (To get rid of the global name 'Don',
select another sheet and delete it in the defined name dialog)

Now when your buttons ref the range by the name 'Don' it will ref cell
'A1' on the sheet that contains the button.

HTH

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default range name define on non active(focused) sheet

On Jan 21, 9:14*pm, GS wrote:
ell brought next idea :

Hi Julliet
the code:
sheets("sheet2").range("a1").name="Don"
is working correctly if I start from sheet2 (from command button on
sheet2 let say)
but from command button in sheet1 ,where the active sheet is sheet1,
from my tests, I noticed
error message on object application...


First thing I'll say here is that unless there's a specific reason to
create global names (ie: workbook level) all defined names should be
made local (ie: sheet level). This removes any/all ambiguity about
defined names withing a workbook. It also allows using duplicate names
on other sheets withing the same workbook.

If you open the defined name dialog while Sheet2 is active, you will
not see the sheetname to the right in the list. If the sheetname isn't
listed to the right then any name missing that are global (workbook
level) So.., to achieve this with naming 'A1' on 'Sheet2' it should
be...

* Sheets("Sheet2").Range("A1").Name = "'Sheet2'!Don"

* **Note that the sheetname is wrapped in apostrophes followed by the
exclamation character. So the syntax for defining local names is...

* *'sheet name'!DefinedName

Now when you open the defined name dialog you'll see 'Sheet2' to the
right of 'Don' in the list. (To get rid of the global name 'Don',
select another sheet and delete it in the defined name dialog)

Now when your buttons ref the range by the name 'Don' it will ref cell
'A1' on the sheet that contains the button.

HTH

--
Garry

Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


you completely right
the Sheet2!Don actually is giving Sheet1!don even I make full
reference to the Names.. .ReferenceTo=Worksheets("Sheet2")....

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 420
Default range name define on non active(focused) sheet

Instead of specifying the sheetname twice, I use something like:

With Worksheets("sheet 2")
.Range("A1").Name = "'" & .Name & "'!Don"
End With



On 01/21/2011 13:14, GS wrote:
Sheets("Sheet2").Range("A1").Name = "'Sheet2'!Don"


--
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
Need VBA Code to Let User Define Active Sheet zulfer7 Excel Discussion (Misc queries) 3 March 29th 07 02:59 PM
Closing the current focused sheet Pietro Excel Discussion (Misc queries) 3 February 22nd 07 11:15 PM
Selecting Range in non-active sheet [email protected] Excel Programming 0 March 27th 06 01:44 PM
Define Name in active cell Danny Excel Worksheet Functions 0 October 13th 05 06:20 PM
define range name, use on VBA selected sheet Bob Swan Excel Programming 0 June 30th 05 02:08 PM


All times are GMT +1. The time now is 08:18 AM.

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"