PC Review


Reply
Thread Tools Rate Thread

copying variable range not working

 
 
Susan
Guest
Posts: n/a
 
      27th Oct 2006
With Sheet2
.Visible = xlSheetVisible
.Cells.Clear
Set MyNewRange = .Range("a1:j500")
Range("a1").Select
End With

With Sheet1
Set MyRange = .Range("a1").End(xlDown).Offset(0, 8)
Range("a1").Select
End With

MyRange.Copy
MyNewRange.PasteSpecial Paste:=xlPasteAll

xxxxxxxxxxxxxxxxxxxxxxx

would somebody please hit me over the head
with a hammer & tell me why this macro
is giving me 500 rows copied of the one cell
located in column "I" in the last row of the
spreadsheet INSTEAD of copying the
range from a1:i<whatever>.

obviously i am TELLING the macro to do
what it is doing; how do i tell it to do what
i want? "MyRange" is the problem. "My
NewRange" works fine (because it's not
variable!).

:c this macro was working perfectly well
but it was a very-newbie one that i am trying
to update with option explicit & making the
code more concise, etc.
thanks for your help & don't use a sledge-
hammer, please.

susan

 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      27th Oct 2006
Set MyRange = .range(range("A1"),Range("a1").End(xlDown)).resize(1, 9)

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Susan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> With Sheet2
> .Visible = xlSheetVisible
> .Cells.Clear
> Set MyNewRange = .Range("a1:j500")
> Range("a1").Select
> End With
>
> With Sheet1
> Set MyRange = .Range("a1").End(xlDown).Offset(0, 8)
> Range("a1").Select
> End With
>
> MyRange.Copy
> MyNewRange.PasteSpecial Paste:=xlPasteAll
>
> xxxxxxxxxxxxxxxxxxxxxxx
>
> would somebody please hit me over the head
> with a hammer & tell me why this macro
> is giving me 500 rows copied of the one cell
> located in column "I" in the last row of the
> spreadsheet INSTEAD of copying the
> range from a1:i<whatever>.
>
> obviously i am TELLING the macro to do
> what it is doing; how do i tell it to do what
> i want? "MyRange" is the problem. "My
> NewRange" works fine (because it's not
> variable!).
>
> :c this macro was working perfectly well
> but it was a very-newbie one that i am trying
> to update with option explicit & making the
> code more concise, etc.
> thanks for your help & don't use a sledge-
> hammer, please.
>
> susan
>



 
Reply With Quote
 
Susan
Guest
Posts: n/a
 
      27th Oct 2006
Bob Phillips wrote:
> Set MyRange = .range(range("A1"),Range("a1").End(xlDown)).resize(1, 9)


thank you very much for that nice
soft tap on the head.
susan

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying a variable range of data from one worksheet to another. AllyB Microsoft Excel Misc 3 2nd Mar 2009 11:37 PM
Copying range to variable number of rows =?Utf-8?B?bm9zcGFtaW5saWNo?= Microsoft Excel Programming 2 1st Dec 2005 11:34 PM
Copying RANGE of variable length =?Utf-8?B?UGVsZQ==?= Microsoft Excel Programming 2 19th Oct 2005 06:00 PM
Copying a variable range Brian Matlack Microsoft Excel Programming 6 17th Oct 2005 03:16 PM
Copying a variable range bobclark@sbc_remove_global.net Microsoft Excel Misc 6 14th Oct 2004 10:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:31 AM.