Excel macro to select and cut multiple rows to a new worksheet

五迷三道 提交于 2020-01-06 04:31:31

问题


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:


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


来源:https://stackoverflow.com/questions/3603911/excel-macro-to-select-and-cut-multiple-rows-to-a-new-worksheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!