VBA: Filter with 2 requirements, then move rows to a new sheet

pramirez98

New Member
Joined
Jul 29, 2011
Messages
4
Can anyone help me with a VBA code for:

Step 1. Filtering:
a. older than today
b. and anything that = 0
Step 2. Move Rows to a different sheet at the next blank row

I've tried using the macro recorder then manipulating the code, but have been unsuccessful. I am a novice at VBA. Please help.

Thanks!!!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Welcome to the MrExcel board!

I have a few questions - in red below.
Can anyone help me with a VBA code for:

Step 1. Filtering: What sheet name?
a. older than today What column?
b. and anything that = 0 What column?
Step 2. Move Rows to a different sheet What sheet name? at the next blank row

I've tried using the macro recorder then manipulating the code, but have been unsuccessful. I am a novice at VBA. Please help.

Thanks!!!
Also, in the original sheet ..

- Does that data start in A1?

- Is there a fixed number of columns? Which columns?
 
Last edited:
Upvote 0
I have assumed that your data starts in column A (you didn't answer my last couple of questions ;) )

I also wasn't sure if the data being copied to sheet2 was supposed to also be removed from sheet1. Post back if that needs to be done and you need assistance.

Test in a copy of your workbook.

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> Filter_Copy()<br>    <SPAN style="color:#00007F">Dim</SPAN> ws1 <SPAN style="color:#00007F">As</SPAN> Worksheet, ws2 <SPAN style="color:#00007F">As</SPAN> Worksheet<br>    <SPAN style="color:#00007F">Dim</SPAN> nr <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, d <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <br>    <SPAN style="color:#00007F">Set</SPAN> ws1 = Sheets("sheet1")<br>    <SPAN style="color:#00007F">Set</SPAN> ws2 = Sheets("sheet2")<br>    <br>    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br>    d = <SPAN style="color:#00007F">Date</SPAN><br>    <SPAN style="color:#00007F">With</SPAN> ws2.UsedRange<br>        nr = .Row + .Rows.Count<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <SPAN style="color:#00007F">With</SPAN> ws1.UsedRange<br>        .AutoFilter Field:=10, Criteria1:="<" & d<br>        .AutoFilter Field:=14, Criteria1:="=0"<br>        .Offset(1).Copy Destination:=ws2.Range("A" & nr)<br>        .AutoFilter<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
This worked great! Would it be difficult to remove the copied data from sheet1? Also when copying data to sheet2 it is being copied to the next empty row?

Thanks, this is really helping out a lot!
 
Upvote 0
Would it be difficult to remove the copied data from sheet1?
Provided your dataset is not too large, try just adding the blue line of code.
Rich (BB code):
.Offset(1).Copy Destination:=ws2.Range("A" & nr)
.Offset(1).EntireRow.Delete
.AutoFilter


Also when copying data to sheet2 it is being copied to the next empty row?
I'm not sure whether that really is a question or a statement. The data should be copied to the next vacant row.
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,683
Members
452,937
Latest member
Bhg1984

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