EXCEL 中怎么用宏实现批量复制相同行
像图中所显示,我要从第4行开始,每行下面,插入粘贴第3的行内容,请问用宏怎么写。不要说复制粘贴后排序,我第3行的内容是公式,不能排序,排序就会出错...
像图中所显示,我要从第4行开始,每行下面,插入粘贴第3的行内容,请问用宏怎么写。不要说复制粘贴后排序,我第3行的内容是公式,不能排序,排序就会出错
展开
1个回答
展开全部
可以的,参考以下宏。
Public Sub Check_for_Duplicate_Rows()
Dim vD As Variant
Dim x As Integer
Dim y As Long
With Worksheets("Data")
vD = .UsedRange.Formula
For x = 2 To UBound(vD, 1)
For y = x + 1 To UBound(vD, 1)
If vD(x, 1) = vD(y, 1) Then
.Rows(y).Copy
Worksheets("Duplicates").Rows(1).Insert
End If
Next y
Next x
End With
End Sub
Public Sub Check_for_Duplicate_Rows()
Dim vD As Variant
Dim x As Integer
Dim y As Long
With Worksheets("Data")
vD = .UsedRange.Formula
For x = 2 To UBound(vD, 1)
For y = x + 1 To UBound(vD, 1)
If vD(x, 1) = vD(y, 1) Then
.Rows(y).Copy
Worksheets("Duplicates").Rows(1).Insert
End If
Next y
Next x
End With
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询