Excel macro to select and cut multiple rows to a n

2019-07-29 11:56发布

I run a report every week and would like to cut the rows for a particular date range into a new worksheet (i.e. all rows with transactions between the 16th of one month to the 15th of the following month).

I'd like to cut all rows between 07/16 and 08/15 and past them in a new worksheet called "Aug" And cut all rows between 08/16 and 09/15 and past them in a new workseet called "Sept"

Example data

Column A - Column B - Column C

Post Date - Name - Vendor

07/25/10 - Wilson - Starbucks

08/05/10 - Wilson - American Airlines

08/14/10 - Guang - Apple Store

08/15/10 - McGee - Staples

08/17/10 - Curry - AT&T

09/02/10 - Johnson - Exxon

09/11/10 - Simms - Old Navy

1条回答
走好不送
2楼-- · 2019-07-29 12:08

Ok, this will work if you have a header row on the destination sheet. I just implemented the August copy and paste, but it would be simple to add September or make it completely generic and have it do the whole year.

Dim workingrow As Range

For Each workingrow In Sheets("Main").Rows

If (workingrow.Cells(1, 1).Value >= DateValue("7/16/2010")) And _ 
   (workingrow.Cells(1, 1).Value <= DateValue("8/15/2010")) Then
        workingrow.Copy (Sheets("Aug").Rows(1).End(xlDown).Offset(1, 0))
End If

Next workingrow
查看更多
登录 后发表回答