假设您有两组数据,并且行和列的数量相同。现在,您要检查一组中单元格中的数据是否与另一组中具有相同相对地址的单元格中的数据相等。如果对某行的所有单元格都为真,则从两个集合中都删除该行。通过比较每个单元格,我可以很轻松地编写此代码,这对大型数据集不利。请参见下面的两列代码,其中两组数据恰好并排在同一张工作表中,并且它们之间的列偏移为300。
Dim RngOb As Range
Dim c As Range
Range("A1", "B1").Select
set RngOb = Range(Selection, Selection.End(xlDown))
For Each c In RngOb.Rows
If c.Cells(1,1).Value = c.Offset(0, 300).Cells(1,1).Value Then
If c.Cells(1,2).Value = c.Offset(0, 300).Cells(1,2).Value Then
c.EntireRow.Delete
End If
End If
Next
我的实际数据每天有100多个列,并且列数不同。我正在寻找一种智能,快速的方法来对大型数据集执行此操作。我高度重视答案,反馈和批评。:D
这是比较同构范围内的两行的一种简单方法.......在此示例中,每个范围的第5行:
Sub RowCompare()
Dim ary1() As Variant
Dim Range1 As Range, Range2 As Range, rr1 As Range, rr2 As Range
Set Range1 = Range("B9:F20")
Set Range2 = Range("I16:M27")
Set rr1 = Range1.Rows(5)
Set rr2 = Range2.Rows(5)
ary1 = Application.Transpose(Application.Transpose(rr1))
ary2 = Application.Transpose(Application.Transpose(rr2))
st1 = Join(ary1, ",")
st2 = Join(ary2, ",")
If st1 = st2 Then
MsgBox "the same"
Else
MsgBox "different"
End If
End Sub
如果您在单元格中嵌入了逗号,则在JOIN中选择另一个字符
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句