我准备了包含我的主数据库的Data
表
A B C
1 ID Col2 Col3
2 800 90 120
3 799 50 110
4 798 80 785
5 797 60 642
6 796 60 212
7 795 26 163
8 794 66 171
9 793 36 673
10 792 16 223
11 791 31 133
12 790 83 253
13 789 33 256
14 788 31 623
我现在要创建另外3张名为TakeAll
,TakeEvery2nd
,TakeEvery4th
我要做的是:
Take All
- 将从Data
表中获取所有数据并将其显示为原始数据:
A B C
1 ID Col2 Col3
2 800 90 120
3 799 50 110
4 798 80 785
5 797 60 642
6 796 60 212
7 795 26 163
8 794 66 171
9 793 36 673
10 792 16 223
11 791 31 133
12 790 83 253
13 789 33 256
14 788 31 623
Take Every 2nd
- 将采取每隔一行,这意味着将采用800
的第一个ID,而不是每隔2个跳过一次(将显示Id的800, 798, 796, 794, 792, 790
)
并且看起来像这样:
A B C
1 ID Col2 Col3
2 800 90 120
4 798 80 785
6 796 60 212
8 794 66 171
10 792 16 223
12 790 83 253
14 788 31 623
Take Every 4th
- 将采取第一行并将采取每第4个含义:
A B C
1 ID Col2 Col3
2 800 90 120
6 796 60 212
10 792 16 223
14 788 31 623
注意:
`Data` will be modified and also new rows are planned to be added
我很难理解如何处理它
答案 0 :(得分:0)
正如我的评论中所述,在“帮助者”中使用MOD function'排列错开的列似乎是一个不错的选择。
Sub break_many()
Dim rw As Long, v As Long, vMODs As Variant, vWSs As Variant
vMODs = Array(1, 2, 4)
vWSs = Array("TakeAll", "TakeEvery2nd", "TakeEvery4th")
With Sheets("Sheet4") '<-set this worksheet reference!
If .AutoFilterMode Then .AutoFilterMode = False
For v = LBound(vMODs) To UBound(vMODs)
With .Cells(1, 1).CurrentRegion
With .Offset(1, .Columns.Count).Resize(.Rows.Count - 1, 1)
.Formula = "=MOD(ROW(1:1)-1, " & vMODs(v) & ")"
End With
End With
With .Cells(1, 1).CurrentRegion
.AutoFilter field:=.Columns.Count, Criteria1:=0
With .Resize(.Rows.Count, .Columns.Count - 1)
.Copy Destination:=Sheets(vWSs(v)).Cells(1, 1)
End With
.AutoFilter field:=.Columns.Count
With .Offset(1, .Columns.Count - 1).Resize(.Rows.Count - 1, 1)
.Clear
End With
End With
Next v
If .AutoFilterMode Then .AutoFilterMode = False
End With
End Sub
这取决于已经存在的三个目标工作表,并且在粘贴数据之前不会清除目标。