Selective Copy Data from Sheet A to Sheet B without Blank Lines

scooter133

New Member
Joined
Oct 7, 2013
Messages
2
I would like to take Data from the "ALL REPS" Sheet and selective Copy out Data from it to another Sheet.

I have the Below code that seems to work, though it has some issue. When it gets to line 10 in 'ARC 5A' it just copies over the same row over and over.
If I remove the Clear Content code, and rerun the Code. I get the same rows appended to the bottom, where the last row get over written. I've tried a vew variants, and all are the same.

Why is my last row getting over written after so many rows?

Thanks!

Code:
Sub Summary()


'Clear Current Contents
Sheets("ARC 5A").Range("A3:AZ65536").Select
Selection.Clear

' Range for the Rows
Dim r As Integer
For r = 2 To 20000
    'This will check the first 20000 rows of the sheet
    '"ALL REPS" Contains All the Data "ARC 5A" Contains Subset of "ALL REPS"

    'ARC 5A  B1 has Search Criteria, "ALL REPS" Column AA Has Field with Data
    If Sheets("ALL REPS").Range("AA" & r).Value = Sheets("ARC 5A").Range("B1").Value Then
      ' Found a Row, Copy it
      Sheets("ALL REPS").Rows(r & ":" & r).Copy

      ' Paste the Row at the End of our "ARC 5A" Sheet
      'Sheets("ARC 5A").Range("A65536").End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
      'Sheets("ARC 5A").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteAll
      Sheets("ARC 5A").Range("A1").End(xlDown).Offset(1, 0).PasteSpecial xlPasteAll

   End If
Next r
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I found out why it kept overwriting the Rows, though not sure how to fix it. Column A has some data in it, though not all Rows do. So when it gets to a row with no data, it starts to overwrite that row. I tried changing to Column D which has Data, though I got Errors.

How can I find the Last ROW with Data in any Column vs a Specific Column?

Thanks!
 
Upvote 0

Forum statistics

Threads
1,216,126
Messages
6,129,007
Members
449,480
Latest member
yesitisasport

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top