Excel Macro deleting unwanted info

Closed
jer - Aug 31, 2010 at 10:38 AM
RayH Posts 122 Registration date Tuesday August 31, 2010 Status Contributor Last seen June 20, 2016 - Sep 2, 2010 at 07:01 PM
Hello,
I am trying to use macro to sort through a lot of data, choose a certain chunk, and copy and paste the chunk to a new file. I am able to copy and paste the chunk I need but then below that chunk it keeps all of the other data. I want it to just be that chunk on the new file. Any suggestions?
Related:

3 responses

From that description, it sounds like you are selecting more than you need, though you state that you are not. If not, how could it be pasted?
Can you post the lines of code that do the selecting and copying followed by the paste code?
0
Columns("C:C").NumberFormat = "0000"
Range("A1:K" & end1).Sort Key1:=Range("C2"), Order1:=xlAscending, Key2:= _
Range("A2"), Order2:=xlDescending, Key3:=Range("B2"), Order3:=xlAscending _
, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:= _
xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal

For t = 2 To end1
Cells(t, 3) = CInt(Cells(t, 3))
Next t

For a = 2 To end1
If Cells(a, 3) <> Cells(a - 1, 3) Then
dealer = Cells(a, 3)
b = a + 11
r = a - 1
Set wk2 = Workbooks.Open("J:\Public\Library\Monthly\Dealer Centric Reports\Template.xls")
wk1.Activate
For n = a To b
If Cells(n, 3) = dealer Then
r = r + 1
End If
Next n
Rows(a & ":" & r).Copy
wk2.Activate
Range("A2").PasteSpecial
0
RayH Posts 122 Registration date Tuesday August 31, 2010 Status Contributor Last seen June 20, 2016 26
Sep 2, 2010 at 07:01 PM
"I am able to copy and paste the chunk I need but then below that chunk it keeps all of the other data"

Sorry, I may have mis-understood what you are trying to achieve. The new file already exists, does it contain data already or is it blank?
Is the data it is keeping in the new file? If so, blank it out first.
0