首页->【软件工具包使用(SW/Software Tools Usage)】

3 1

Option Explicit
Public Function ItemNumberChk()
   
   Dim row As Integer
   Dim cnti As Integer, cntj As Integer

   Dim tmpValA As String
   Dim tmpValB As String
   
   Dim TestItemColNo As Integer
   
   Dim DupFlg As Integer
   'Dim Red As Integer
   
   'Red = RGB(0, 0, 10)
   TestItemColNo = 4
   
   'calc the row cnt
   With Sheet1
            .Activate
            .Range("D1:D512").Select
            For cnti = 2 To 512
                If Cells(cnti, TestItemColNo).Value <> "" Then
                         row = row + 1
                End If
            Next cnti
            For cnti = 2 To row - 1
                  tmpValA = .Cells(cnti, TestItemColNo).Value
                For cntj = cnti + 1 To row
                  tmpValB = .Cells(cntj, TestItemColNo).Value
                  If tmpValA = tmpValB Then
                    DupFlg = DupFlg + 1
                      .Cells(cnti, TestItemColNo).Interior.ColorIndex = DupFlg + 1
                      .Cells(cntj, TestItemColNo).Interior.ColorIndex = DupFlg + 1
                 Else
                   'DupFlg = 0
                  End If
                Next cntj
            Next cnti
            
   End With
   
   If DupFlg >= 1 Then
        Call MsgBox("Error:dupicated TestItemNo Pls Chk", 0)
   End If
   
End Function

楼主可见

  1. shwnyoo 1#

    VBA 列单元格重复项检查   ,代码已验证