ReDim arrCell(1 To lRows * lCols, 0 To 2) As String Dim i As Long Dim j As Long Dim arrCount As Long Dim m As Long
arrCount = 0 For i = 1 To lRows For j = 1 To lCols arrCount = arrCount + 1 arrCell(arrCount, 0) = i arrCell(arrCount, 1) = j arrCell(arrCount, 2) = Excel.ActiveWorkbook.Sheets(1).Cells(i, j) Next Next
Dim s1 As String Dim s2 As String For i = 1 To lRows For j = 1 To lCols s1 = Excel.ActiveWorkbook.Sheets(1).Cells(i, j) s1 = Trim(s1) For m = 1 To arrCount If arrCell(m, 0) = i And arrCell(m, 1) = j Then Else s2 = arrCell(m, 2) s2 = Trim(s2) If s1 = s2 Then MsgBox ("重复单元格:" & Str(i) & "," & Str(j) & " 与 " & Str(arrCell(m, 0)) & "," & Str(arrCell(m, 1))) Exit For End If End If Next Next Next
Dim lRows As Long
Dim lCols As Long
Dim arrCell() As String
lRows = Sheet1.Cells.SpecialCells(xlCellTypeLastCell).Row
lCols = Sheet1.Cells.SpecialCells(xlCellTypeLastCell).Column
ReDim arrCell(1 To lRows * lCols, 0 To 2) As String
Dim i As Long
Dim j As Long
Dim arrCount As Long
Dim m As Long
arrCount = 0
For i = 1 To lRows
For j = 1 To lCols
arrCount = arrCount + 1
arrCell(arrCount, 0) = i
arrCell(arrCount, 1) = j
arrCell(arrCount, 2) = Excel.ActiveWorkbook.Sheets(1).Cells(i, j)
Next
Next
Dim s1 As String
Dim s2 As String
For i = 1 To lRows
For j = 1 To lCols
s1 = Excel.ActiveWorkbook.Sheets(1).Cells(i, j)
s1 = Trim(s1)
For m = 1 To arrCount
If arrCell(m, 0) = i And arrCell(m, 1) = j Then
Else
s2 = arrCell(m, 2)
s2 = Trim(s2)
If s1 = s2 Then
MsgBox ("重复单元格:" & Str(i) & "," & Str(j) & " 与 " & Str(arrCell(m, 0)) & "," & Str(arrCell(m, 1)))
Exit For
End If
End If
Next
Next
Next