对于列B中的每个组,我希望标识列A中最近一天添加的值或上个月删除的值。
结果:
我设法在一个简化的例子中做到了这一点,但没有在上面的格式中做到,在上面的格式中,数据按字段一个在另一个下面存储。
Sub CompareSheetsV2()
Dim wsA As Worksheet
Dim wsB As Worksheet
Dim rngA As Range
Dim rngB As Range
Dim cellA As Range
Dim cellB As Range
Dim found As Range
Set wsA = ThisWorkbook.Worksheets("a")
Set rngA = wsA.Range("A2:A" & wsA.Cells(wsA.Rows.Count, "A").End(xlUp).Row)
Set rngB = wsA.Range("B2:B" & wsA.Cells(wsA.Rows.Count, "B").End(xlUp).Row)
For Each cellA In rngA
Set found = rngB.Find(cellA.Value, LookIn:=xlValues)
If found Is Nothing Then
cellA.Offset(0, 5).Value = cellA.Value
cellA.Offset(0, 6).Value = "deleted"
Else
End If
Next cellA
For Each cellB In rngB
Set found = rngA.Find(cellB.Value, LookIn:=xlValues)
If found Is Nothing Then
wsA.Cells(wsA.Rows.Count, "F").End(xlUp).Offset(1, 0).Value = cellB.Value
wsA.Cells(wsA.Rows.Count, "G").End(xlUp).Offset(1, 0).Value = "added"
Else
End If
Next cellB
End Sub
1条答案
按热度按时间q43xntqr1#
这也可以使用Windows Excel 2010+和Excel 365(Windows或Mac)中提供的Power Query来完成
使用增强查询的步骤
Home => Advanced Editor
Applied Steps
以理解算法在PQ中转置后