2,462
社区成员
发帖
与我相关
我的任务
分享
' Excel VBA代码:
Public Sub Proc()
Dim strText As String
Dim i&, j&, k As Long
Dim w&, u&, v As Long
u = WorksheetFunction.CountA(Sheet1.Range("A:A"))
i = 1& ' 数据从第1行开始
Do
If (i > u) Then Exit Do
strText = Sheet1.Cells(i, 1).Text
v = Sheet1.Cells(i, 2).Value
k = 0&
j = i
Do
j = 1& + j
If (j > u) Then Exit Do
If (strText = Sheet1.Cells(j, 1).Text) Then
w = Sheet1.Cells(j, 2).Value
If (w > v) Then v = w: k = vbTrue
Call Sheet1.Rows(j).Delete
u = u - 1&
End If
Loop
If (k) Then Sheet1.Cells(i, 2).Value = v
i = 1& + i
Loop
End Sub