查找最大数字并删除剩余的最小数字

时间:2018-02-07 23:31:24

标签: vba excel-vba excel

我试图通过比较同一列中的名称来删除单元格,如果我找到相同的名称,那么请确保名称后面包含更大的数字 斜杠,如果我找到更大的数字,那么请确保我的C列符合我的标准(不播放)。如果它匹配则删除所有小数字的单元格,其中列c表示静止播放并且只保留更大的数字,表示不播放。任何想法,我已经发布了我的代码但是当我找到一个更大的数字时,它会回来并与另一个单元格进行比较,以便它回到相同的数字。这是我的代码..

Sub xm()
    Dim lastrow As Long
    Dim i As Long, firstD As Integer, secondD As Integer
    Dim firstForward As Integer
    Dim secondForward As Integer, score1 As String, score2 As String
    Dim fName As String, sName As String
    lastrow = ActiveSheet.UsedRange.Rows.Count

      For i = 2 To lastrow

          firstD = InStr(1, ActiveSheet.Cells(i, 1), "/")
          fName = Left(ActiveSheet.Cells(i, 1), firstD - 1)
          secondD = InStr(1, ActiveSheet.Cells(i + 1, 1), "/")
          sName = Left(ActiveSheet.Cells(i + 1, 1), secondD - 1)

              If fName = sName Then
                 firstForward = InStr(1, ActiveSheet.Cells(i, 1), "/")
                 score1 = Mid(ActiveSheet.Cells(i, 4), firstForward + 1)
                 secondForward = InStr(1, ActiveSheet.Cells(i + 1, 4), "/")
                 score2 = Mid(ActiveSheet.Cells(i + 1, 4), firstForward + 1)

                   If score1 > score2 Then
                      If ActiveSheet.Cells(i, 3) = "Not Playing" Then
                      'Delete entire cell
                      End If

                   End If
              End If
       i = i + 1
      Next i
End Sub

enter image description here

输出:---

enter image description here

0 个答案:

没有答案