我有2列数据(带标题),其中A(顺序)总是有重复(有时2-3),但B数据(也是连续的)总是唯一的,并且dupes是不存在的。我从@Jeeped找到了这个解决方案并进行了修改以满足需求 - 显然不起作用,因为我不知道如何在代码中定义max(B)。
Sub RemoDupeMaxB()
Dim wb1 As Workbook
Dim lr As Long, i As Long
Set wb1 = Workbooks(“Survey Beta.xlsm")
With wb1.Sheets("VERT SCALES")
lr = Application.Max(.Cells(Rows.Count, 1).End(xlUp).Row, _
.Cells(Rows.Count, 2).End(xlUp).Row)
For i = lr To 1 Step -1
If .Cells(i, 1).Value > '??? And _
(.Cells(i, 2).Value > Max(B:B)) Then
.Rows(i).EntireRow.Delete
End If
Next i
End With
End Sub
我希望vba做的是使用max(B)的条件来删除(行)来自A的所有其他欺骗 - 保留最大(B)行数据。
答案 0 :(得分:1)
我想我会用双for循环解决这个问题,就像这样
Sub RemoDupeMaxB()
Dim wb1 As Workbook
Dim lr As Long, i As Long
Set wb1 = Workbooks(“Survey Beta.xlsm")
With wb1.Sheets("VERT SCALES")
lr = Application.Max(.Cells(Rows.Count, 1).End(xlUp).Row, _
.Cells(Rows.Count, 2).End(xlUp).Row)
For i = lr To 1 Step -1
for j = i - 1 to 1 Step -1
If .Cells(i, 1).Value = .Cells(j, 1).Value And _
.Cells(i, 2).Value > .Cells(j, 2).Value Then
.Rows(j).EntireRow.Delete
End If
Next j
Next i
End With
End Sub