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 Problem

I'm having trouble understanding a simple behavior of Ranges. In the
following snippet...

Sub test()
Dim rng As Range

Worksheets("Sheet1").Select
Set rng = Range("A1:A10")

Charts("Chart1").Select

Debug.Print rng.Address ' OK - Prints $A$1:$A$10

rng.Value = 10 ' <-- Works OK
rng.Select ' <-- Fails: Run-time Error 1004: Method
'Select' of object 'Range' failed
End Sub

If I can write to the range with "rng.Value =", why can't I select the range
with "rng.Select"? It seems to me both should work.

Steve

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Range Problem

You set rng to Sheet1!A1:A10, but then you select a Chart sheet.
You can't select a cell that is not on the active sheet.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Steven Drenker" wrote in
message
...
I'm having trouble understanding a simple behavior of Ranges.
In the
following snippet...

Sub test()
Dim rng As Range

Worksheets("Sheet1").Select
Set rng = Range("A1:A10")

Charts("Chart1").Select

Debug.Print rng.Address ' OK - Prints $A$1:$A$10

rng.Value = 10 ' <-- Works OK
rng.Select ' <-- Fails: Run-time Error 1004: Method
'Select' of object 'Range' failed
End Sub

If I can write to the range with "rng.Value =", why can't I
select the range
with "rng.Select"? It seems to me both should work.

Steve



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,316
Default Range Problem

The object with the focus is your chart, if you reactivate the worksheet your
range select statement works just fine.

ActiveWorkbook.Sheets("Sheet1").Activate
--
Kevin Backmann


"Steven Drenker" wrote:

I'm having trouble understanding a simple behavior of Ranges. In the
following snippet...

Sub test()
Dim rng As Range

Worksheets("Sheet1").Select
Set rng = Range("A1:A10")

Charts("Chart1").Select

Debug.Print rng.Address ' OK - Prints $A$1:$A$10

rng.Value = 10 ' <-- Works OK
rng.Select ' <-- Fails: Run-time Error 1004: Method
'Select' of object 'Range' failed
End Sub

If I can write to the range with "rng.Value =", why can't I select the range
with "rng.Select"? It seems to me both should work.

Steve


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Range Problem

Hi Steven

Range("A1:A10") refers to a range of cells
Range 10 is not a range of cells, hence the error message.
Also, you can only set ranges with Set, not with Value



"Steven Drenker" wrote:

I'm having trouble understanding a simple behavior of Ranges. In the
following snippet...

Sub test()
Dim rng As Range

Worksheets("Sheet1").Select
Set rng = Range("A1:A10")

Charts("Chart1").Select

Debug.Print rng.Address ' OK - Prints $A$1:$A$10

rng.Value = 10 ' <-- Works OK
rng.Select ' <-- Fails: Run-time Error 1004: Method
'Select' of object 'Range' failed
End Sub

If I can write to the range with "rng.Value =", why can't I select the range
with "rng.Select"? It seems to me both should work.

Steve


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Range Problem

Yes, you must first select the sheet, then the cell. You can do
it on one line of code with Application.Goto. E.g.,

Application.Goto Rng


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Steven Drenker" wrote in
message
...
in article , Chip Pearson
at
wrote on 1/23/06 10:51 AM:

You set rng to Sheet1!A1:A10, but then you select a Chart
sheet.
You can't select a cell that is not on the active sheet.

Thanks, Chip. So I need to do it in two steps? First select the
sheet and
then select the cell? I can't combine into one step such as
ws.range.select?



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
3D range problem br549 Excel Worksheet Functions 1 June 15th 07 08:52 PM
Range problem Ali Baba Excel Programming 2 September 15th 05 10:54 PM
Range problem David Gerstman Excel Programming 2 May 24th 05 07:11 PM
Used Range Problem Charles Williams Excel Programming 0 August 4th 03 08:30 AM
Used Range Problem Donald Lloyd Excel Programming 6 August 3rd 03 10:18 PM


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

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"