如果满足其他列的条件,则删除偏移值的行

问题描述 投票:0回答:1

如果另外满足另外三列 E、G、H、M、N 的条件,我将尝试删除从 K 列中相互偏移的项目的行。

enter image description here

!(因此,如果 E、G、H、M、N 列中的条件相同,并且 K 列中我们有抵消金额,则应删除该行。 有人可以帮我吗?)

excel vba
1个回答
0
投票

这个宏可以帮助你:

Sub DeleteRows()
  Dim i As Long, j As Long, lr As Long, a() As Boolean
  lr = [E2].End(xlDown).Row
  ReDim a(2 To lr) As Boolean
  For i = 2 To lr - 1
    If Not a(i) Then
      For j = i + 1 To lr
        If Not a(j) And Cells(j, "E") = Cells(i, "E") _
            And Cells(j, "G") = Cells(i, "G") _
            And Cells(j, "H") = Cells(i, "H") _
            And Cells(j, "M") = Cells(i, "M") _
            And Cells(j, "N") = Cells(i, "N") _
            And Cells(j, "K") = -Cells(i, "K") _
        Then
          a(i) = True: a(j) = True
          Exit For
        End If
      Next
    End If
  Next
  For i = lr To 2 Step -1
    If a(i) Then Rows(i).Delete
  Next
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.