[英]How do you compare a column in two worksheets?
Can someone tell me how to compare only one column instead of the whole sheet? 有人可以告诉我如何只比较一栏而不是整张纸吗? thank you.
谢谢。
Sub Compare() 子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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.