PC Review


Reply
Thread Tools Rate Thread

Copy, paste, sort, copy paste

 
 
=?Utf-8?B?U2hlbGx5?=
Guest
Posts: n/a
 
      28th Feb 2007
Hi - I am trying to figure out the code to copy a range, paste it to the same
worksheet, sort the range, then copy the sorted data to another workhsheet.

This is what I have...

Private Sub ACSButton_Click()
ACSButton.Caption = "Click Here to Load ACS Services"
Worksheets("Solution Map").Activate
Worksheets("Solution Map").Range("Source1").Copy
ActiveSheet.Paste Destination:=Worksheets("Solution
Map").Range("Source2")
'Worksheets("Solution Map").Range("Source2").Select
'Worksheet("Solution Map").Range("Source2").Copy
Selection.Sort Key1:=Worksheets("Solution Map").Range("J36"),
Order1:=xlDescending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Selection.Copy
Worksheets("ACS").Activate
ActiveSheet.Paste Destination:=Worksheets("ACS").Range("Target")
Selection.PasteSpecial xlPasteValues
End Sub

But, it's giving me an 1004 error (The sort reference is not valid. Make
sure it's within the data you want to sort, and the first Sort By Box isn't
the same or blank.) on the "Selection.Sort" line.

Source1 is a named range in Solution Map
Source2 is the location where the copied data is pasted, the sorted, also in
Solution Map
I want to paste to a worksheet named ACS, to the named range "Target".

HELP!

 
Reply With Quote
 
 
 
 
=?Utf-8?B?T3NzaWVNYWM=?=
Guest
Posts: n/a
 
      28th Feb 2007
Where and when are the ranges for Source1 and Source2 set?
Try inserting the following code as the first line and check that they are
in fact set.

MsgBox ("Source1 address is " & Source1.Address & _
Chr(13) & "Source2 address is " & Source2.Address)




"Shelly" wrote:

> Hi - I am trying to figure out the code to copy a range, paste it to the same
> worksheet, sort the range, then copy the sorted data to another workhsheet.
>
> This is what I have...
>
> Private Sub ACSButton_Click()
> ACSButton.Caption = "Click Here to Load ACS Services"
> Worksheets("Solution Map").Activate
> Worksheets("Solution Map").Range("Source1").Copy
> ActiveSheet.Paste Destination:=Worksheets("Solution
> Map").Range("Source2")
> 'Worksheets("Solution Map").Range("Source2").Select
> 'Worksheet("Solution Map").Range("Source2").Copy
> Selection.Sort Key1:=Worksheets("Solution Map").Range("J36"),
> Order1:=xlDescending, Header:=xlNo, _
> OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
> Selection.Copy
> Worksheets("ACS").Activate
> ActiveSheet.Paste Destination:=Worksheets("ACS").Range("Target")
> Selection.PasteSpecial xlPasteValues
> End Sub
>
> But, it's giving me an 1004 error (The sort reference is not valid. Make
> sure it's within the data you want to sort, and the first Sort By Box isn't
> the same or blank.) on the "Selection.Sort" line.
>
> Source1 is a named range in Solution Map
> Source2 is the location where the copied data is pasted, the sorted, also in
> Solution Map
> I want to paste to a worksheet named ACS, to the named range "Target".
>
> HELP!
>

 
Reply With Quote
 
=?Utf-8?B?U2hlbGx5?=
Guest
Posts: n/a
 
      28th Feb 2007
I've given up on using the named ranges... and have gone back to referencing
by Row and Column.... here's what I have now (it's the ever-changing code)...

Sub ACSButton_Click()
ACSButton.Caption = "Click Here to Load ACS Services"
Sheets("Solution Map").Select
Range("F36:I201").Copy
Worksheets("Solution Map").Range("J36").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
True, Transpose:=False
Application.CutCopyMode = False
Range("J36:M201").Sort Key1:=Range("J36"), Order1:=xlDescending,
Key2:=Range( _
"K36"), Order2:=xlDescending, Key3:=Range("L36"),
Order3:=xlDescending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom
Selection.Copy
Sheets("ACS").Select
Range("A8").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
True, Transpose:=False
Range("A8").Select
End Sub

THanks.
 
Reply With Quote
 
=?Utf-8?B?T3NzaWVNYWM=?=
Guest
Posts: n/a
 
      28th Feb 2007
Disregard my last advice. I confused myself with setting a range in code not
naming a range.

I have tested your code and it works. Check that the key range("J36") in the
sort is the correct first cell in the Source2.

I notice you have 2 lines commented out. You need to uncomment the first
line to select the range before sorting.
The second line not required but note it should have an s on the end of
worksheet if you use it.




"OssieMac" wrote:

> Where and when are the ranges for Source1 and Source2 set?
> Try inserting the following code as the first line and check that they are
> in fact set.
>
> MsgBox ("Source1 address is " & Source1.Address & _
> Chr(13) & "Source2 address is " & Source2.Address)
>
>
>
>
> "Shelly" wrote:
>
> > Hi - I am trying to figure out the code to copy a range, paste it to the same
> > worksheet, sort the range, then copy the sorted data to another workhsheet.
> >
> > This is what I have...
> >
> > Private Sub ACSButton_Click()
> > ACSButton.Caption = "Click Here to Load ACS Services"
> > Worksheets("Solution Map").Activate
> > Worksheets("Solution Map").Range("Source1").Copy
> > ActiveSheet.Paste Destination:=Worksheets("Solution
> > Map").Range("Source2")
> > 'Worksheets("Solution Map").Range("Source2").Select
> > 'Worksheet("Solution Map").Range("Source2").Copy
> > Selection.Sort Key1:=Worksheets("Solution Map").Range("J36"),
> > Order1:=xlDescending, Header:=xlNo, _
> > OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
> > Selection.Copy
> > Worksheets("ACS").Activate
> > ActiveSheet.Paste Destination:=Worksheets("ACS").Range("Target")
> > Selection.PasteSpecial xlPasteValues
> > End Sub
> >
> > But, it's giving me an 1004 error (The sort reference is not valid. Make
> > sure it's within the data you want to sort, and the first Sort By Box isn't
> > the same or blank.) on the "Selection.Sort" line.
> >
> > Source1 is a named range in Solution Map
> > Source2 is the location where the copied data is pasted, the sorted, also in
> > Solution Map
> > I want to paste to a worksheet named ACS, to the named range "Target".
> >
> > HELP!
> >

 
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
Copy/paste/sort JockW Microsoft Excel Programming 1 16th Jan 2010 11:53 AM
VBA copy paste sort refresh inkexit@yahoo.com Microsoft Excel Programming 0 27th Oct 2006 05:09 PM
Sort, Copy, Paste..without Autofilter..Anyone??? jeffg Microsoft Excel Worksheet Functions 1 19th Oct 2005 05:34 PM
Copy & Paste Object without using the Excel Copy Paste functions =?Utf-8?B?R2Fueg==?= Microsoft Excel New Users 0 10th Mar 2004 07:06 AM
Copy & Paste Object without using the Excel Copy Paste functions =?Utf-8?B?R2Fueg==?= Microsoft Excel Misc 0 10th Mar 2004 07:06 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:12 AM.