Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default syntax - range name as a variable



I can select a named range like so :

range ("range_01").select

this works. but I want to make the selected range a variable like this:

range_string = "range_01"
range (range_string).select

This gives me error messages "method range of object global failed"


What is the correct syntax for doing this?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default syntax - range name as a variable

Works for me. Did you declare range_string as string?

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Peter Morris" <nospam.ple@se wrote in message
.uk...


I can select a named range like so :

range ("range_01").select

this works. but I want to make the selected range a variable like this:

range_string = "range_01"
range (range_string).select

This gives me error messages "method range of object global failed"


What is the correct syntax for doing this?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default syntax - range name as a variable


"Bob Phillips" wrote in message
...
Works for me. Did you declare range_string as string?



Yes, I did.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default syntax - range name as a variable

You can only select a range if the worksheet that owns the range is active.

And you can only select a worksheet if the workbook that owns the worksheet is
active.

So you can pepper your code with

workbooks("book1.xls").activate
workbooks("book1.xls").worksheets("sheet1").select
workbooks("book1.xls").worksheets("sheet1").range( "range_01").select

or use

application.goto _
workbooks("book1.xls").worksheets("sheet1").range( "range_01"), _
scroll:=true '?

======
And depending on where your code is (is it behind a worksheet?), you could have
the problem because an unqualified range (range("range_01") belongs to the
worksheet that holds the code.

And that might not be where the range really is (and it blows up real good).


Peter Morris wrote:

I can select a named range like so :

range ("range_01").select

this works. but I want to make the selected range a variable like this:

range_string = "range_01"
range (range_string).select

This gives me error messages "method range of object global failed"

What is the correct syntax for doing this?


--

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
Deleting a range of rows based on a variable; syntax error Babymech Excel Discussion (Misc queries) 3 January 16th 09 06:19 PM
macro syntax for selecting variable range Matt Excel Discussion (Misc queries) 1 October 31st 07 07:13 PM
syntax when using a variable in a formula anny Excel Programming 2 May 8th 06 04:09 PM
syntax for variable adamaagard Excel Programming 2 January 20th 06 12:45 AM
Syntax to Set variable range Mike Fogleman Excel Programming 3 December 10th 05 09:11 PM


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