Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Using Cells Method to define Ranges

I have a question regarding refering to ranges. Below is some sample
(and simple) code to illustrate my question. I prefer to use R1C1
notation and the cells property. But I have to use the A1 notation
when I set the range "r" in the code below. Why can't I replace that
line with:

Set r = y.Range(cells(1,1),cells(3,3))

This line returns the " Method 'Range' or object '_Worksheet' failed "
error.

Thanks for the help,
John

Sub junk()

Dim xyz As Workbook
Dim x As Worksheet
Dim y As Worksheet
Dim z As Worksheet
Dim r As Range

Set xyz = ActiveWorkbook
abc.Activate
'
Set x = xyz.Worksheets("X")
Set y = xyz.Worksheets("Y")
Set z = xyz.Worksheets("Z")

Set r = y.Range("A1:C3")
r.Font.Bold = True

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default Using Cells Method to define Ranges

The following worked for me when I dimensioned 'abc' and set it to
another workbook. See the following:

Sub junk()
Dim xyz As Workbook
Dim x As Worksheet
Dim y As Worksheet
Dim z As Worksheet
Dim r As Range

'assuming abc is a workbook
Dim abc As Workbook
Set abc = Workbooks("book1")

Set xyz = ActiveWorkbook
abc.Activate

Set x = xyz.Worksheets("X")
Set y = xyz.Worksheets("Y")
Set z = xyz.Worksheets("Z")

Set r = y.Range("A1:C3")
r.Font.Bold = True
End Sub

HTH--Lonnie M.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default Using Cells Method to define Ranges

I need to work on my listening/reading skills I guess--sorry about
that.
Try activating the sheet that you are setting the range to. I am pretty
sure that setting the range in this manner requires the range to be set
from the activesheet.

Sub junk()
Dim xyz As Workbook
Dim x As Worksheet
Dim y As Worksheet
Dim z As Worksheet
Dim r As Range

'assuming abc is a workbook
Dim abc As Workbook
Set abc = Workbooks("book1")

Set xyz = ActiveWorkbook
' abc.Activate

Set x = xyz.Worksheets("X")
Set y = xyz.Worksheets("Y")
Set z = xyz.Worksheets("Z")

xyz.Activate
y.Activate
Set r = y.Range(Cells(1, 1), Cells(3, 3))
r.Font.Bold = True
End Sub

Regards--Lonnie M.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Using Cells Method to define Ranges

Because RANGE() wants a text string as an argument, try:


Set r = y.Range(Cells(1, 1).Address, Cells(3, 3).Address)
--
Gary's Student


" wrote:

I have a question regarding refering to ranges. Below is some sample
(and simple) code to illustrate my question. I prefer to use R1C1
notation and the cells property. But I have to use the A1 notation
when I set the range "r" in the code below. Why can't I replace that
line with:

Set r = y.Range(cells(1,1),cells(3,3))

This line returns the " Method 'Range' or object '_Worksheet' failed "
error.

Thanks for the help,
John

Sub junk()

Dim xyz As Workbook
Dim x As Worksheet
Dim y As Worksheet
Dim z As Worksheet
Dim r As Range

Set xyz = ActiveWorkbook
abc.Activate
'
Set x = xyz.Worksheets("X")
Set y = xyz.Worksheets("Y")
Set z = xyz.Worksheets("Z")

Set r = y.Range("A1:C3")
r.Font.Bold = True

End Sub


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
What does it mean define ranges in Excell for import Ron New Users to Excel 2 September 7th 06 05:38 PM
How select/define cells with FIND method (maybe together with SpecialCells) Marie J-son[_5_] Excel Programming 2 December 14th 04 03:49 PM
Automatically define series of named ranges Jon Tillman Excel Programming 7 June 18th 04 07:39 AM
Does RangeFromPoint Method return ranges? Bernie Deitrick Excel Programming 4 May 5th 04 09:51 PM
union method for non-adjacent ranges Jim Rech Excel Programming 0 September 16th 03 02:17 PM


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