Can someone tell me how to compare only one column instead of the whole sheet? thank you.
Sub Compare()
Call compareSheets("Sofon", "Sofontest")
End Sub
Sub compareSheets(Sofon As String, Sofontest As String)
Dim mycell As Range
Dim mydiffs As Integer
For Each mycell In ActiveWorkbook.Worksheets(Sofontest).UsedRange
If Not mycell.Value = ActiveWorkbook.Worksheets(Sofon).Cells(mycell.Row, mycell.Column).Value Then
mycell.Interior.Color = vbYellow
mydiffs = mydiffs + 1
End If
Next
MsgBox mydiffs & " differences found", vbInformation
ActiveWorkbook.Sheets(Sofontest).Select
End Sub
Call compareSheets("Sofon", "Sofontest", "B1:B900")
End Sub
Sub compareSheets(Sofon As String, Sofontest As String, sRange as String)
Dim mycell As Range
Dim mydiffs As Integer
For Each mycell In ActiveWorkbook.Worksheets(Sofontest).sRange
If Not mycell.Value = ActiveWorkbook.Worksheets(Sofon).Cells(mycell.Row, mycell.Column).Value Then
mycell.Interior.Color = vbYellow
mydiffs = mydiffs + 1
End If
Next
MsgBox mydiffs & " differences found", vbInformation
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.