Excel宏可以选择和剪切多行到一个新的工作表 [英] Excel macro to select and cut multiple rows to a new worksheet
问题描述
我每周运行一个报告,并希望将特定日期范围的行切成一个新的工作表(即所有行在一个月的16个月到下个月的15日之间)。
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).
我想剪切07/16和08/15之间的所有行,并通过名为Aug的新工作表
并切割08/16之间的所有行和09/15,并通过他们在一个名为九月的新工作集
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"
示例数据
列A - 列B - 列C
Column A - Column B - Column C
发布日期 - 名称 - 供应商
Post Date - Name - Vendor
07 / 25/10 - 威尔逊 - 星巴克
07/25/10 - Wilson - Starbucks
08/05/10 - 威尔逊 - 美国航空公司
08/05/10 - Wilson - American Airlines
08/14 / 10 - 广 - 苹果店
08/14/10 - Guang - Apple Store
08/15/10 - McGee - Staples
08/15/10 - McGee - Staples
08/17 / 10 - 咖喱 - AT& T
08/17/10 - Curry - AT&T
09/02/10 - Johnson - Exxon
09/02/10 - Johnson - Exxon
09/11 / 10 - Simms - 旧海军
09/11/10 - Simms - Old Navy
推荐答案
好的,如果你在目标上有一个标题行工作表。我刚刚实施了8月份的复制和粘贴,但是添加9月可能很简单,也可以使其完全通用,并且全年都可以。
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
这篇关于Excel宏可以选择和剪切多行到一个新的工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!