Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
sgl sgl is offline
external usenet poster
 
Posts: 80
Default What am I doing wrong?

Hi All,
I am using Excel 2000 with Windows XP. I have the following code to capture
the actual range of cells

Range("A5",Range("G5").End(xlDown)).Select

This works well. Also the following works well.

Set sourceRange=mybook.worksheets(5).Range("A5").Curre ntRegion

In both the above instances the workbook in aopen and active.

Applying the same logic as follows does not work for me but gives me an
"Application or Object defined error". mybook is a closed Workbook.

Set sourceRange=mybook.Worksheets(5).Range("A5",Range( "G5").End(xlDown))

Any ideas what am I doing wrong.

Thanks in advance/sgl
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default What am I doing wrong?

Hi SGL,

Try changing:

Set sourceRange=mybook.Worksheets(5).Range("A5",Range( "G5").End(xlDown))


to:

With mybook.Sheets(5)
Set SourceRange = .Range("A5", .Range("G5").End(xlDown))
End With

Your problem is one of qualification: in your original expression:

Range("G5")

is not qualified (with its parent sheet) and, therefore, this is interpreted
as relating to cell G5 on the active sheet. If the active sheet is not
sheet(5), then you are asking VBA to construct a range which spans 2 sheets.
Since this is not possible, you get the error message.


---
Regards,
Norman



"sgl" wrote in message
...
Hi All,
I am using Excel 2000 with Windows XP. I have the following code to
capture
the actual range of cells

Range("A5",Range("G5").End(xlDown)).Select

This works well. Also the following works well.

Set sourceRange=mybook.worksheets(5).Range("A5").Curre ntRegion

In both the above instances the workbook in aopen and active.

Applying the same logic as follows does not work for me but gives me an
"Application or Object defined error". mybook is a closed Workbook.

Set sourceRange=mybook.Worksheets(5).Range("A5",Range( "G5").End(xlDown))

Any ideas what am I doing wrong.

Thanks in advance/sgl



  #3   Report Post  
Posted to microsoft.public.excel.programming
sgl sgl is offline
external usenet poster
 
Posts: 80
Default What am I doing wrong?

Nrman,
You saved my day !. Thanks a lot for the quick response. Worked a treat
Regards/sgl

"Norman Jones" wrote:

Hi SGL,

Try changing:

Set sourceRange=mybook.Worksheets(5).Range("A5",Range( "G5").End(xlDown))


to:

With mybook.Sheets(5)
Set SourceRange = .Range("A5", .Range("G5").End(xlDown))
End With

Your problem is one of qualification: in your original expression:

Range("G5")

is not qualified (with its parent sheet) and, therefore, this is interpreted
as relating to cell G5 on the active sheet. If the active sheet is not
sheet(5), then you are asking VBA to construct a range which spans 2 sheets.
Since this is not possible, you get the error message.


---
Regards,
Norman



"sgl" wrote in message
...
Hi All,
I am using Excel 2000 with Windows XP. I have the following code to
capture
the actual range of cells

Range("A5",Range("G5").End(xlDown)).Select

This works well. Also the following works well.

Set sourceRange=mybook.worksheets(5).Range("A5").Curre ntRegion

In both the above instances the workbook in aopen and active.

Applying the same logic as follows does not work for me but gives me an
"Application or Object defined error". mybook is a closed Workbook.

Set sourceRange=mybook.Worksheets(5).Range("A5",Range( "G5").End(xlDown))

Any ideas what am I doing wrong.

Thanks in advance/sgl




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
Insert Calculated Field (wrong Qty*Price = wrong Amount) Edmund Excel Discussion (Misc queries) 8 October 4th 07 12:13 PM
Any wrong with this? Jo[_2_] Excel Discussion (Misc queries) 1 August 2nd 07 09:48 PM
What's wrong? Newbie Excel Programming 2 November 26th 04 01:47 PM
Am I doing something wrong here? TyeJae[_21_] Excel Programming 2 June 29th 04 12:56 AM
What is wrong?? willroy[_2_] Excel Programming 1 December 12th 03 01:33 PM


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