Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default MsgBox including range value

I've played around with this, and looked at other posts. Still can't
get this right.
I want to show a MsgBox with a message & also the value of a range.
Here's what I've got so far. Any help would be appreciated. I'm
getting a 1004 error. Method 'range of object'_Global' failed.
I've tried variations of this:

MsgBox "Miles remaining until next oil change: " & Range
(NextOilChg_Chev).Value

Note: This is all in 1 line in the module.
Thanks
j.o.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default MsgBox including range value

Jeff,

For this to work you must have a named range set on the worksheet called
NextOilChg_Chev

MsgBox "Miles remaining until next oil change: " &
Range("NextOilChg_Chev").Value

and in the code it must be in quotes ""

Mike

"jeff" wrote:

I've played around with this, and looked at other posts. Still can't
get this right.
I want to show a MsgBox with a message & also the value of a range.
Here's what I've got so far. Any help would be appreciated. I'm
getting a 1004 error. Method 'range of object'_Global' failed.
I've tried variations of this:

MsgBox "Miles remaining until next oil change: " & Range
(NextOilChg_Chev).Value

Note: This is all in 1 line in the module.
Thanks
j.o.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default MsgBox including range value

On Sep 25, 12:58*pm, Mike H wrote:
Jeff,

For this to work you must have a named range set on the worksheet called
NextOilChg_Chev

MsgBox "Miles remaining until next oil change: *" &
Range("NextOilChg_Chev").Value

and in the code it must be in quotes ""

Mike



"jeff" wrote:
I've played around with this, and looked at other posts. Still can't
get this right.
I want to show a MsgBox with a message & also the value of a range.
Here's what I've got so far. Any help would be appreciated. I'm
getting a 1004 error. Method 'range of object'_Global' failed.
I've tried variations of this:


MsgBox "Miles remaining until next oil change: *" & Range
(NextOilChg_Chev).Value


Note: This is all in 1 line in the module.
Thanks
j.o.- Hide quoted text -


- Show quoted text -


Thanks Mike.
I already had the range named. BUT, I didn't even notice the quotes
for the range name was missing....
I appreciate the fast response.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default MsgBox including range value

Named ranges are a bit tricky to refer to in code. What you have here

Range("NextOilChg_Chev").Value
is translated to
Activesheet.Range("NextOilChg_Chev").Value

If NextOilChg_Chev is not on the acive sheet then the code crashes. To refer
to global named ranges you are best off to use

application.names("NextOilChg_Chev").referstorange .value

This avoids the sheet reference entirely. So your code should be

MsgBox "Miles remaining until next oil change: " & _
application.names("NextOilChg_Chev").referstorange .value

--
HTH...

Jim Thomlinson


"jeff" wrote:

I've played around with this, and looked at other posts. Still can't
get this right.
I want to show a MsgBox with a message & also the value of a range.
Here's what I've got so far. Any help would be appreciated. I'm
getting a 1004 error. Method 'range of object'_Global' failed.
I've tried variations of this:

MsgBox "Miles remaining until next oil change: " & Range
(NextOilChg_Chev).Value

Note: This is all in 1 line in the module.
Thanks
j.o.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default MsgBox including range value

On Sep 25, 1:13*pm, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote:
Named ranges are a bit tricky to refer to in code. What you have here

Range("NextOilChg_Chev").Value
is translated to
Activesheet.Range("NextOilChg_Chev").Value

If NextOilChg_Chev is not on the acive sheet then the code crashes. To refer
to global named ranges you are best off to use

application.names("NextOilChg_Chev").referstorange .value

This avoids the sheet reference entirely. So your code should be

MsgBox "Miles remaining until next oil change: *" & _
*application.names("NextOilChg_Chev").referstorang e.value

--
HTH...

Jim Thomlinson



"jeff" wrote:
I've played around with this, and looked at other posts. Still can't
get this right.
I want to show a MsgBox with a message & also the value of a range.
Here's what I've got so far. Any help would be appreciated. I'm
getting a 1004 error. Method 'range of object'_Global' failed.
I've tried variations of this:


MsgBox "Miles remaining until next oil change: *" & Range
(NextOilChg_Chev).Value


Note: This is all in 1 line in the module.
Thanks
j.o.- Hide quoted text -


- Show quoted text -


Thanks for the help, Jim. I did not know this. Very efficient! I
appreciate it.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default MsgBox including range value

Jim,

Range("NextOilChg_Chev").Value
is translated to
Activesheet.Range("NextOilChg_Chev").Value


That isn't strictly correct. In a standard module the simplified version I
gave will always work no matter which sheet is active. Likewise in worksheet
code 'provided' the named range is in the same sheet as the code.

I agree it will fail as worksheet code if the named range is in another sheet.

Mike

"Jim Thomlinson" wrote:

Named ranges are a bit tricky to refer to in code. What you have here

Range("NextOilChg_Chev").Value
is translated to
Activesheet.Range("NextOilChg_Chev").Value

If NextOilChg_Chev is not on the acive sheet then the code crashes. To refer
to global named ranges you are best off to use

application.names("NextOilChg_Chev").referstorange .value

This avoids the sheet reference entirely. So your code should be

MsgBox "Miles remaining until next oil change: " & _
application.names("NextOilChg_Chev").referstorange .value

--
HTH...

Jim Thomlinson


"jeff" wrote:

I've played around with this, and looked at other posts. Still can't
get this right.
I want to show a MsgBox with a message & also the value of a range.
Here's what I've got so far. Any help would be appreciated. I'm
getting a 1004 error. Method 'range of object'_Global' failed.
I've tried variations of this:

MsgBox "Miles remaining until next oil change: " & Range
(NextOilChg_Chev).Value

Note: This is all in 1 line in the module.
Thanks
j.o.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default MsgBox including range value

Glad I could help and thanks for the feedback

"jeff" wrote:

On Sep 25, 12:58 pm, Mike H wrote:
Jeff,

For this to work you must have a named range set on the worksheet called
NextOilChg_Chev

MsgBox "Miles remaining until next oil change: " &
Range("NextOilChg_Chev").Value

and in the code it must be in quotes ""

Mike



"jeff" wrote:
I've played around with this, and looked at other posts. Still can't
get this right.
I want to show a MsgBox with a message & also the value of a range.
Here's what I've got so far. Any help would be appreciated. I'm
getting a 1004 error. Method 'range of object'_Global' failed.
I've tried variations of this:


MsgBox "Miles remaining until next oil change: " & Range
(NextOilChg_Chev).Value


Note: This is all in 1 line in the module.
Thanks
j.o.- Hide quoted text -


- Show quoted text -


Thanks Mike.
I already had the range named. BUT, I didn't even notice the quotes
for the range name was missing....
I appreciate the fast response.

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
Including in a range [email protected] Excel Discussion (Misc queries) 1 April 18th 07 03:58 PM
Copy Range including Formats and Forumulas ALV Excel Programming 1 February 23rd 07 09:15 PM
multiple lookup including date range JonW Excel Worksheet Functions 3 February 12th 07 02:45 PM
MAX/MIN in range potantially including text TrackStats Excel Worksheet Functions 1 February 5th 07 06:21 AM
Average range including blank cells: #DIV/0! Areaka Excel Worksheet Functions 3 April 12th 06 10:21 PM


All times are GMT +1. The time now is 04:55 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"