Hello All,
Hoping to get your input on a compare excel worksheet problem. I have two tabs (OLD and NEW), the OLD tab contains data from the previous month and NEW tab contains data from the current month. Each tab has 2000 plus rows and 25 columns. Data in OLD tab can be in NEW tab. Also, the data is not in the same order and the NEW tab can have more or less rows. I am trying to do the following:
1. Highlight/Print in DIFF tab the first 10 columns that are in NEW but not OLD - do not match
2. Highlight OLD items that are not in NEW tab - cells that do not match
My problem is that the data is not rows in both tabs are not equal. SkipV was kind enough to provide the below, but it is not working the way I describe above
Sub compareSheets(shtSheet1 As String, shtSheet2 As String)
Dim mycell As Range, xl As Application
Dim mydiffs As Integer
Set xl = Application
'For each cell in sheet2 that is not the same in Sheet1, color it yellow
With ActiveWorkbook
For Each mycell In .Worksheets(shtSheet2).UsedRange
If IsError(xl.Match(mycell.Value, .Worksheets(shtSheet1).Columns(mycell.Column), 0)) Then
mycell.Interior.Color = vbYellow
mydiffs = mydiffs + 1
End If
Next
'Display a message box to demonstrate the differences
MsgBox mydiffs & " differences found", vbInformation
.Sheets(shtSheet2).Select
End With
Set xl = Nothing
End Sub
Hoping to get your input on a compare excel worksheet problem. I have two tabs (OLD and NEW), the OLD tab contains data from the previous month and NEW tab contains data from the current month. Each tab has 2000 plus rows and 25 columns. Data in OLD tab can be in NEW tab. Also, the data is not in the same order and the NEW tab can have more or less rows. I am trying to do the following:
1. Highlight/Print in DIFF tab the first 10 columns that are in NEW but not OLD - do not match
2. Highlight OLD items that are not in NEW tab - cells that do not match
My problem is that the data is not rows in both tabs are not equal. SkipV was kind enough to provide the below, but it is not working the way I describe above
Sub compareSheets(shtSheet1 As String, shtSheet2 As String)
Dim mycell As Range, xl As Application
Dim mydiffs As Integer
Set xl = Application
'For each cell in sheet2 that is not the same in Sheet1, color it yellow
With ActiveWorkbook
For Each mycell In .Worksheets(shtSheet2).UsedRange
If IsError(xl.Match(mycell.Value, .Worksheets(shtSheet1).Columns(mycell.Column), 0)) Then
mycell.Interior.Color = vbYellow
mydiffs = mydiffs + 1
End If
Next
'Display a message box to demonstrate the differences
MsgBox mydiffs & " differences found", vbInformation
.Sheets(shtSheet2).Select
End With
Set xl = Nothing
End Sub