شنبه یازدهم مرداد ۱۳۹۹ - 14:11 - حسين حسين پور -
This VBA code checks all the cells from a column and highlights all the cells which are duplicate within each column.
In simple words, if a column has the value “231” twice then it will be considered as duplicate. But if the another “231” is in another column then it will be considered as unique.
Sub DuplicateValuesFromColumns() 'Declare All Variables Dim myCell As Range Dim myRow As Integer Dim myRange As Range Dim myCol As Integer Dim i As Integer 'Count number of rows & column myRow = Range(Cells(1, 1), Cells(1, 1).End(xlDown)).Count myCol = Range(Cells(1, 1), Cells(1, 1).End(xlToRight)).Count 'Loop each column to check duplicate values & highlight them. For i = 2 To myRow Set myRange = Range(Cells(2, i), Cells(myRow, i)) For Each myCell In myRange If WorksheetFunction.CountIf(myRange, myCell.Value) > 1 Then myCell.Interior.ColorIndex = 3 End If Next Next End Sub