Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Easy code, confounded by error

I'm simply trying to get the text stored in a cell that has its own named range. I keep getting a "Method 'Range' of 'object _Global' failed" error. Here is the code:

Dim temp As String
temp = Range("statusBarMsg").Value2

What can I be missing here? Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Easy code, confounded by error

That error might be because the Name doesn't exist, or it doesn't refer to a
range, or it refers to more than one cell, or it has refers to a range
that's been removed (a ref error), or it's a worksheet level name and the
sheet is not active.

How far do you get with this

Dim rng As Range
Dim nm As Name
Set nm = ActiveWorkbook.Names("statusBarMsg")
Set rng = nm.RefersToRange
Debug.Print rng.Address
Debug.Print rng.Value2

Regards,
Peter T


wrote in message
...
I'm simply trying to get the text stored in a cell that has its own named
range. I keep getting a "Method 'Range' of 'object _Global' failed" error.
Here is the code:

Dim temp As String
temp = Range("statusBarMsg").Value2

What can I be missing here? Thanks.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 829
Default Easy code, confounded by error

wrote:
I keep getting a "Method 'Range' of 'object _Global' failed"
error. Here is the code:
Dim temp As String
temp = Range("statusBarMsg").Value2
What can I be missing here?


With Name Manager, take a close look at how statusBarMsg is defined, if at
all. I wonder if the scope is a specific worksheet, not workbook, and when
you execute the line above, ActiveSheet is not worksheet scope defined for
statusBarMsg.

Alternatively, put the following in place of the code above and execute
(just for diagnostic purposes):

Dim nm
For Each nm In ActiveWorkbook.Names
If InStr(nm.Name, "statusBarMsg") Then MsgBox nm.Name
Next

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Easy code, confounded by error

On Wednesday, July 11, 2012 2:59:43 PM UTC-6, Peter T wrote:
That error might be because the Name doesn't exist, or it doesn't refer to a
range, or it refers to more than one cell, or it has refers to a range
that's been removed (a ref error), or it's a worksheet level name and the
sheet is not active.

How far do you get with this

Dim rng As Range
Dim nm As Name
Set nm = ActiveWorkbook.Names("statusBarMsg")
Set rng = nm.RefersToRange
Debug.Print rng.Address
Debug.Print rng.Value2

Regards,
Peter T


<
> I'm simply trying to get the text stored in a cell that has its own named
> range. I keep getting a "Method 'Range' of 'object _Global' failed" error.
> Here is the code:
>
> Dim temp As String
> temp = Range("statusBarMsg").Value2
>
> What can I be missing here? Thanks.


Thank you. I actually solved this by simply adding a worksheet reference in front of the range reference. As in sheet1.range("statusBarMsg")...

Thanks for your help. I appreciate it.
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
Confounded by date differences DubboPete Excel Discussion (Misc queries) 3 March 4th 10 12:07 AM
confused and confounded! salgud Excel Programming 7 July 18th 08 03:30 PM
Easy VB code question Anthony Excel Discussion (Misc queries) 2 July 8th 05 08:45 PM
Easy code!!!! Sudhendra Excel Programming 4 February 18th 04 08:31 PM
Easy Value listing code Todd Huttenstine[_2_] Excel Programming 1 November 29th 03 10:01 AM


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

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

About Us

"It's about Microsoft Excel"