G
Gani tpt
Guest
I have two workbook.
Each workbook will have different sheets.
When both workbook sheets are the same, then it should check every individual cell of both the sheet.
let us imagine, both the sheet start range A20:KJ20
Sheet1 ==> A21 cell value is "12"
Sheet2 ==> A21 cell value is "14".
the above value is different, then it should show the difference in various color in "Sheet1"
I have done some code below.
But, worksheet not showing the range.
Dim varSheetCurr As Object
Dim varSheetPrev As Object
Dim strRangeToCheck As String
Dim iRow As Long
Dim iCol As Long
strRangeToCheck = "A21:IV65536"
' If you know the data will only be in a smaller range, reduce the size of the ranges above.
Debug.Print(Now)
varSheetCurr = Worksheets("Sheet2").Range(strRangeToCheck)
varSheetPrev = Worksheets("Sheet2").Range(strRangeToCheck) ' or whatever your other sheet is.
Debug.Print(Now)
For iRow = LBound(varSheetCurr, 1) To UBound(varSheetCurr, 1)
For iCol = LBound(varSheetCurr, 2) To UBound(varSheetCurr, 2)
If varSheetCurr(iRow, iCol) = varSheetPrev(iRow, iCol) Then
' Cells are identical.
' Do nothing.
Else
' Cells are different.
' Code goes here for whatever it is you want to do.
Worksheets("Sheet1").Cells(iRow, iCol).Interior.Color = 255
End If
Next iCol
Next iRow
What is the problem in the above code...?
Continue reading...
Each workbook will have different sheets.
When both workbook sheets are the same, then it should check every individual cell of both the sheet.
let us imagine, both the sheet start range A20:KJ20
Sheet1 ==> A21 cell value is "12"
Sheet2 ==> A21 cell value is "14".
the above value is different, then it should show the difference in various color in "Sheet1"
I have done some code below.
But, worksheet not showing the range.
Dim varSheetCurr As Object
Dim varSheetPrev As Object
Dim strRangeToCheck As String
Dim iRow As Long
Dim iCol As Long
strRangeToCheck = "A21:IV65536"
' If you know the data will only be in a smaller range, reduce the size of the ranges above.
Debug.Print(Now)
varSheetCurr = Worksheets("Sheet2").Range(strRangeToCheck)
varSheetPrev = Worksheets("Sheet2").Range(strRangeToCheck) ' or whatever your other sheet is.
Debug.Print(Now)
For iRow = LBound(varSheetCurr, 1) To UBound(varSheetCurr, 1)
For iCol = LBound(varSheetCurr, 2) To UBound(varSheetCurr, 2)
If varSheetCurr(iRow, iCol) = varSheetPrev(iRow, iCol) Then
' Cells are identical.
' Do nothing.
Else
' Cells are different.
' Code goes here for whatever it is you want to do.
Worksheets("Sheet1").Cells(iRow, iCol).Interior.Color = 255
End If
Next iCol
Next iRow
What is the problem in the above code...?
Continue reading...