Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Range problems...

Hello All,

If I have the following code:

-------------------
Dim MyRange As Range

Set MyRange = "B19:I26"
-------------------

How can i get the Active worksheet (or any other worksheet) to select that
same range.

ActiveSheet.Range(MyRange).Select

wont work because Range expects 2 arguments.

TIA,

Neil.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Range problems...

The problem is that you're not properly using the Range data type and
the Set keyword. If you use MyRange as a Range object, it's only going
to apply to the specific sheet and range you used when you set it
(ActiveSheet by default). To generalize the range for all sheets,
there are (at least) two ways to do it:

First:
---------------
Dim MyRange as String

MyRange = "B19:I26"
Worksheet(<Whatever).Range(MyRange).Select
---------------

Second:
---------------
Dim MyRange as Range

Set MyRange = Range("B19:I26")
Worksheet(<Whatever).Range(MyRange.Address).Selec t
---------------

The first is probably best because you save a little memory (especially
if it's in a loop).

Let me know if that doesn't make sense.
Mark

Neil wrote:
Hello All,

If I have the following code:

-------------------
Dim MyRange As Range

Set MyRange = "B19:I26"
-------------------

How can i get the Active worksheet (or any other worksheet) to select

that
same range.

ActiveSheet.Range(MyRange).Select

wont work because Range expects 2 arguments.

TIA,

Neil.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Range problems...


"Neil" wrote in message
...
Hello All,

If I have the following code:

-------------------
Dim MyRange As Range

Set MyRange = "B19:I26"


It will fail as you cannot set a range objcet to a string.

You should use

Set MyRange = Range("B19:I26")

-------------------

How can i get the Active worksheet (or any other worksheet) to select that
same range.


Then you just use

Activesheet.MyRange.Select

ActiveSheet.Range(MyRange).Select

wont work because Range expects 2 arguments.


Where do you get that idea from? You have two syntaxes for Range
Syntax 1

expression.Range(Cell1)

Syntax 2

expression.Range(Cell1, Cell2)


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Range problems...

A few other points:

If you are talking about the active worksheet, you can just do Range().Select

Unless you need to re-use your range address, you can specify it directly,
e.g. Range("B19:I26").Select.

Finally, you will not be able to use Range.Select on a sheet if it is not
active; if ot talking about the active sheet, before you select you need to
activate the sheet, e.g.:
Worksheets("Sheet2").Activate
Worksheets("Sheet2").Range("B19:I26").Select

"Mark Bigelow" wrote:

The problem is that you're not properly using the Range data type and
the Set keyword. If you use MyRange as a Range object, it's only going
to apply to the specific sheet and range you used when you set it
(ActiveSheet by default). To generalize the range for all sheets,
there are (at least) two ways to do it:

First:
---------------
Dim MyRange as String

MyRange = "B19:I26"
Worksheet(<Whatever).Range(MyRange).Select
---------------

Second:
---------------
Dim MyRange as Range

Set MyRange = Range("B19:I26")
Worksheet(<Whatever).Range(MyRange.Address).Selec t
---------------

The first is probably best because you save a little memory (especially
if it's in a loop).

Let me know if that doesn't make sense.
Mark

Neil wrote:
Hello All,

If I have the following code:

-------------------
Dim MyRange As Range

Set MyRange = "B19:I26"
-------------------

How can i get the Active worksheet (or any other worksheet) to select

that
same range.

ActiveSheet.Range(MyRange).Select

wont work because Range expects 2 arguments.

TIA,

Neil.



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
problems editing data range wn Excel Discussion (Misc queries) 1 September 7th 07 10:52 PM
Range name problems Andrea Jones Excel Discussion (Misc queries) 1 October 18th 06 01:36 AM
Macro problems with range and naming issues Vapanda[_3_] Excel Programming 1 June 2nd 04 01:26 AM
Range problems fred 616 Excel Programming 7 May 24th 04 04:11 AM
Variables and range problems athuggard Excel Programming 2 December 30th 03 08:12 PM


All times are GMT +1. The time now is 01:32 AM.

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"