
excel中:在N行N列数据中,如何用涵数查找相同位置的两(或N)个数字?谢谢!如下图
3个回答
展开全部
你是说在这些数据中找到有两个(或多个)相同位置数字相同的单元格,并标记为黄颜色,用vba可轻松实现
Sub Mac1()
Dim nRow As Integer
Dim nCol As Integer
Dim tmpRow As Integer
Dim tmpCol As Integer
Dim tmpTmpRow As Integer
Dim nBook As Workbook
Dim n As Integer
Dim tmpn As Integer
Dim myArray() As Integer
Set nBook = ThisWorkbook
nRow = nBook.Sheets(1).UsedRange.Rows.Count
nCol = nBook.Sheets(1).UsedRange.Columns.Count
ReDim myArray(nCol)
For tmpRow = 1 To nRow - 1
For tmpTmpRow = tmpRow + 1 To nRow
n = 0
For tmpCol = 1 To nCol
If Cells(tmpTmpRow, tmpCol) = Cells(tmpRow, tmpCol) Then
myArray(n) = tmpCol
n = n + 1
End If
Next
If n >= 2 Then
For tmpn = 0 To n - 1
Cells(tmpRow, myArray(tmpn)).Interior.ColorIndex = 6
Cells(tmpTmpRow, myArray(tmpn)).Interior.ColorIndex = 6
Next
End If
Next
Next
End Sub
Sub Mac1()
Dim nRow As Integer
Dim nCol As Integer
Dim tmpRow As Integer
Dim tmpCol As Integer
Dim tmpTmpRow As Integer
Dim nBook As Workbook
Dim n As Integer
Dim tmpn As Integer
Dim myArray() As Integer
Set nBook = ThisWorkbook
nRow = nBook.Sheets(1).UsedRange.Rows.Count
nCol = nBook.Sheets(1).UsedRange.Columns.Count
ReDim myArray(nCol)
For tmpRow = 1 To nRow - 1
For tmpTmpRow = tmpRow + 1 To nRow
n = 0
For tmpCol = 1 To nCol
If Cells(tmpTmpRow, tmpCol) = Cells(tmpRow, tmpCol) Then
myArray(n) = tmpCol
n = n + 1
End If
Next
If n >= 2 Then
For tmpn = 0 To n - 1
Cells(tmpRow, myArray(tmpn)).Interior.ColorIndex = 6
Cells(tmpTmpRow, myArray(tmpn)).Interior.ColorIndex = 6
Next
End If
Next
Next
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询