返回列表 上一主題 發帖

資料比對

資料比對

A~E欄內,同一列中B欄與D欄比較/C欄與E欄比較,將不一樣的複製到M~Q欄
請問如何用VBA執行
A  B  C   D  E
1  0  aa  0  aa
2  1  bb 2  cc
3  1  dd 1 dd
4  2  zz  2  zz
5  6  aa  7 aa

不同的複製到
M N O  P  Q
2  1  bb 2  cc
5  6  aa  7 aa

{=INDEX(A:A,SMALL(IF(MMULT(($B$2:$C$6=$D$2:$E$6)*1,{1;1})<2,ROW(C$2:C$6),4^8),ROW(B1)))&""
google"EXCEL迷"  blog  或google網址:https://hcm19522.blogspot.com/

TOP

回復 2# hcm19522
謝謝指導,我再研究看看

TOP

已解決,謝謝大家
Sub Ex()
Dim Ay(4), Ary(), C As Range
With Sheets(1)
    For Each C In .Range(.[a2], .[a2].End(xlDown))
          If .Cells(C.Row, 3) <> .Cells(C.Row, 5) Or .Cells(C.Row, 4) <> .Cells(C.Row, 6) Then
          Ay(0) = .Cells(C.Row, 1): Ay(1) = .Cells(C.Row, 2): Ay(2) = .Cells(C.Row, 3): Ay(3) = .Cells(C.Row, 4)
          Ay(4) = .Cells(C.Row, 5)
          ReDim Preserve Ary(s)
          Ary(s) = Ay
          Erase Ay: s = s + 1
          End If
   Next
End With
Sheets(1).Range("m1:q65526").Clear
Sheets(1).[m1].Resize(s, 5) = Application.Transpose(Application.Transpose(Ary))
End Sub

TOP

回復 4# jcchiang

您可能是誤植~

下式:
If .Cells(C.Row, 3) <> .Cells(C.Row, 5) Or .Cells(C.Row, 4) <> .Cells(C.Row, 6) Then

應改為:
If .Cells(C.Row, 2) <> .Cells(C.Row, 4) Or .Cells(C.Row, 3) <> .Cells(C.Row, 5) Then

TOP

回復 5# Kubi
感謝提醒,已修正

TOP

        靜思自在 : 心中常存善解、包容、感思、知足、惜福。
返回列表 上一主題