Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Code won't work?

[code]
Worksheets("Sheet1").Select (or Activate)
[end code]

causes a breakout from Application.ScreenUpdating=false

So I am trying to reference the range I need using:

[code]
Worksheets("Sheet1").Range("J2", Range("J2").End(xlDown)). Copy
Worksheets("Sheet2").Range("b2")
[end code]

but I get an object error. I need to reference the range with .End because
the size of range starting at J2 will keep changing.

All/any help greatly appreciated & sorry for the double post (?)

Joe


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default Code won't work?

Joe,

I assume you are on another sheet when you get this error? I think it is
because that in these circumstances the first Range refers to Sheet1, but
the second is not fully qualified, so it refers to the active sheet.

Try

With Worksheets("Sheet1")
.Range("J2", .Range("J2").End(xlDown)).Copy
End With


not the dots before the Range keywords.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Joe 90" wrote in message
...
[code]
Worksheets("Sheet1").Select (or Activate)
[end code]

causes a breakout from Application.ScreenUpdating=false

So I am trying to reference the range I need using:

[code]
Worksheets("Sheet1").Range("J2", Range("J2").End(xlDown)). Copy
Worksheets("Sheet2").Range("b2")
[end code]

but I get an object error. I need to reference the range with .End because
the size of range starting at J2 will keep changing.

All/any help greatly appreciated & sorry for the double post (?)

Joe




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Code won't work?


Bob

Your extra "dots" worked a treat, and this will help me enormously with my
coding. just wish I properly understood the science behind it, although I
see what you say about the second range not being qualified.

Joe90

Calling from the Wild Hills of Winchester!



"Bob Phillips" wrote in message
...
Joe,

I assume you are on another sheet when you get this error? I think it is
because that in these circumstances the first Range refers to Sheet1, but
the second is not fully qualified, so it refers to the active sheet.

Try

With Worksheets("Sheet1")
.Range("J2", .Range("J2").End(xlDown)).Copy
End With


not the dots before the Range keywords.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Joe 90" wrote in message
...
[code]
Worksheets("Sheet1").Select (or Activate)
[end code]

causes a breakout from Application.ScreenUpdating=false

So I am trying to reference the range I need using:

[code]
Worksheets("Sheet1").Range("J2", Range("J2").End(xlDown)). Copy
Worksheets("Sheet2").Range("b2")
[end code]

but I get an object error. I need to reference the range with .End

because
the size of range starting at J2 will keep changing.

All/any help greatly appreciated & sorry for the double post (?)

Joe






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Code won't work?

The science behind the With...End With structure is pretty simple:

1) The "." is used as shorthand for whatever follows the With, so


With Worksheets("Sheet1")
.Range("J2", .Range("J2").End(xlDown)).Copy
End With

is shorter, and perhaps faster to write than

Worksheets("Sheet1").Range("J2", _
Worksheets("Sheet1").Range("J2").End(xlDown)).Copy

2) In the second example, the Worksheets("Sheet1") reference has to
be resolved twice. Using With...End With, the worksheets("Sheet1")
reference is only resolved once. Resolving object (Workbook,
Worksheet, Range, etc.) references is very time and resource
consuming, so the With...End With structure is also more efficient
any time you have more than one reference to an object.


In article ,
"Joe 90" wrote:

Your extra "dots" worked a treat, and this will help me enormously with my
coding. just wish I properly understood the science behind it, although I
see what you say about the second range not being qualified.

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
Why does this code not work? rk0909 Excel Discussion (Misc queries) 12 September 4th 08 10:42 PM
Why this code is not work? Error code when select worksheet Excel Worksheet Functions 4 December 4th 07 12:51 AM
Why my code do not work : - ( keepitcool Excel Programming 5 September 5th 03 06:28 PM
Why my code do not work : - ( Tom Ogilvy Excel Programming 1 August 31st 03 04:53 PM
Why my code do not work : - ( Bob Phillips[_5_] Excel Programming 0 August 31st 03 01:27 PM


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