Macro to Copy & Paste only rows with data

KWorsham

New Member
Joined
Apr 5, 2010
Messages
7
I have the following issue:
Rows are populated with data based on date listed (Rows 6-20). The formula puts a " " if the date cell is blank since the range of data is not the same each time the data pull is imported. What I need is a macro that only copies and then pastes to another sheet ("ARCHIVE") the rows that have data; could be rows 6-20, 6-15 or just row 6.

excel_example.JPG

Thank you in advance for any time and assistance given to my little issue.
:help:
 
Last edited:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
In the example, rows 6-10 have data and 11-20 have " ". But next time the data is pulled, it could be that rows 6-10 or even just row 6 that could have data and the remaining rows through 20 would have the " ".
 
Upvote 0
Sorry...I'm a dork... read "column" but heard "row" in my head. :oops:
Columns B:ANU but the headers are already on the "ARCHIVE" tab so would only need the data copied over.
 
Upvote 0
Sorry but I am still not understanding. You want to copy rows 6:20 where something doesn't contain " ". What is that something?
 
Upvote 0
Rows 6-20 could contain data or " ". What I would like a macro to do is to copy and paste into the "ARCHIVE" sheet but each time, I need it to only copy the rows that do have data. Would it be easier if the rows that had didn't have data but had " " were a certain fill color and then I could have the macro copy and paste only the rows with that color?
 
Upvote 0
Assuming column B contains the " "


Code:
Sub test()
Dim i As Integer
For i = 6 To 20
    If Range("B" & i) <> " " Then Rows(i).Copy Destination:=Sheets("ARCHIVE").Range("A" & Rows.Count).End(xlUp).Offset(1)
Next i
End Sub
 
Upvote 0
Just reading through this marco code as looking to use it myself.

How would I change it to copy into another Workbook rather than another sheet?

Thanks!
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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