发布网友 发布时间:2022-04-25 11:43
共2个回答
热心网友 时间:2024-10-12 07:03
其实这样做最简便的方法是通过“数据”选项下的“高级”筛选来实现。
将1中的条件复制到2中数据区域外,然后在“高级筛选”中,以2的“数据区域”为“列表区域”,以复制并筛选到2中的条件为“条件区域”,勾选“将筛选结果复制到其他位置”,并指定2中的某一个位置,确定,即可。
然后复制筛选结果到3中,结束。
热心网友 时间:2024-10-12 07:03
Sub 复制订单()
Set sh1 = Sheets("1")
Set sh2 = Sheets("2")
Set sh3 = Sheets("3")
hs1 = sh1.UsedRange.Rows.Count
hs2 = sh2.UsedRange.Rows.Count
h = 1
For i = 2 To hs1
sj = sh1.Cells(i, 2)
For j = 1 To hs2
If sh2.Cells(j, 4) = sj Then
sh2.Rows(j).Copy sh3.Cells(h, 1)
h = h + 1
End If
Next
Next
End Sub
excel2007下调试非常完美!请采纳!追问如果在“1”中,订单号重复的话,怎么样才能做到不重复提取。
追答Sub 复制订单()
Set sh1 = Sheets("1")
Set sh2 = Sheets("2")
Set sh3 = Sheets("3")
hs1 = sh1.UsedRange.Rows.Count
hs2 = sh2.UsedRange.Rows.Count
h = 1
Dim cf As Boolean
For i = 2 To hs1
sj = sh1.Cells(i, 2)
cf = False
For k = 1 To i - 1
If sh1.Cells(k, 2) = sj Then
cf = True
Exit For
End If
Next k
If cf = False Then
For j = 1 To hs2
If sh2.Cells(j, 4) = sj Then
sh2.Rows(j).Copy sh3.Cells(h, 1)
h = h + 1
End If
Next j
End If
Next i
End Sub