Checking the Difference between 2 sheets and highlight the difference with the column saying “Difference”?










0















I have 2 sheets with one offline data and one online data from a DB server and want to sort the difference between the two sheets and highlight the difference and count the difference and display the counting value in the end column if its there else have to say "same" in the end column.
For eg: Sheet 1



 A B C D 
T1 T2 T3 T4
T1 T2 T3 T4


Sheet 2



 A B C D 
T1 T2 T3 T4
T1 T2 T4 T5


Result--> sheet 3 should be



 A B C D E 
T1 T2 T3 T4
T1 T2 T3 T4 Same
T1 T2 T3 T4
T1 T2 T4 T5 2 difference


The Code i have is highlighting the difference but not Pasting the Sheet 1 value in the Sheet 3.My end result will be comparing the Same row and cell between the Sheet1 snd Sheet2 and have to paste the difference in the sheet 3 with pasting both rows consecutively. Any help is highly appreciated.



Sub Compare()
Dim ColumnCount, RowCount As Long
Dim w As Worksheet, r As Range

'Clearing the contents of the third sheet for the fresh comparison

usedCoulms = ThisWorkbook.Worksheets("Sheet4").UsedRange.Columns.Count
usedRows = ThisWorkbook.Worksheets("Sheet4").UsedRange.Rows.Count
For i = 1 To usedRows
For j = 1 To usedCoulms
Sheets("Sheet4").Cells(i, j).Value = ""
Sheets("Sheet4").Cells(i, j).Interior.Color = RGB(255, 255, 255)
Next
Next

'Coulmn count of first sheet
ColumnCount = ThisWorkbook.Worksheets("Sheet1").UsedRange.Columns.Count
'row count of first sheet
RowCount = ThisWorkbook.Worksheets("Sheet1").UsedRange.Rows.Count

For i = 1 To RowCount

For j = 1 To ColumnCount
If Sheets("Sheet1").Cells(i, j).Value <> Sheets("Sheet2").Cells(i, j).Value Then 'Comparing if values are not equal
Sheets("Sheet4").Cells(i, j).Value = Sheets("Sheet1").Cells(i, j).Value 'Copying the Header of the Mismatched Cell
Sheets("Sheet4").Cells(i, j).Value = Sheets("Sheet2").Cells(i, j).Value 'CStr("MisMatch") 'If mismatch setting set value as MisMatch
Sheets("Sheet4").Cells(i, j).Interior.Color = 65535 'Highlighting with Yellow color
Else
Sheets("Sheet4").Cells(i, j).Value = Sheets("Sheet2").Cells(i, j).Value
'If values are same copy the first sheets value if dont want to copy can skip this
End If

Next
Next
MsgBox "SORTINGCOMPLETE"
End Sub









share|improve this question
























  • Don't tag spam.

    – shmosel
    Nov 16 '18 at 3:28















0















I have 2 sheets with one offline data and one online data from a DB server and want to sort the difference between the two sheets and highlight the difference and count the difference and display the counting value in the end column if its there else have to say "same" in the end column.
For eg: Sheet 1



 A B C D 
T1 T2 T3 T4
T1 T2 T3 T4


Sheet 2



 A B C D 
T1 T2 T3 T4
T1 T2 T4 T5


Result--> sheet 3 should be



 A B C D E 
T1 T2 T3 T4
T1 T2 T3 T4 Same
T1 T2 T3 T4
T1 T2 T4 T5 2 difference


The Code i have is highlighting the difference but not Pasting the Sheet 1 value in the Sheet 3.My end result will be comparing the Same row and cell between the Sheet1 snd Sheet2 and have to paste the difference in the sheet 3 with pasting both rows consecutively. Any help is highly appreciated.



Sub Compare()
Dim ColumnCount, RowCount As Long
Dim w As Worksheet, r As Range

'Clearing the contents of the third sheet for the fresh comparison

usedCoulms = ThisWorkbook.Worksheets("Sheet4").UsedRange.Columns.Count
usedRows = ThisWorkbook.Worksheets("Sheet4").UsedRange.Rows.Count
For i = 1 To usedRows
For j = 1 To usedCoulms
Sheets("Sheet4").Cells(i, j).Value = ""
Sheets("Sheet4").Cells(i, j).Interior.Color = RGB(255, 255, 255)
Next
Next

'Coulmn count of first sheet
ColumnCount = ThisWorkbook.Worksheets("Sheet1").UsedRange.Columns.Count
'row count of first sheet
RowCount = ThisWorkbook.Worksheets("Sheet1").UsedRange.Rows.Count

For i = 1 To RowCount

For j = 1 To ColumnCount
If Sheets("Sheet1").Cells(i, j).Value <> Sheets("Sheet2").Cells(i, j).Value Then 'Comparing if values are not equal
Sheets("Sheet4").Cells(i, j).Value = Sheets("Sheet1").Cells(i, j).Value 'Copying the Header of the Mismatched Cell
Sheets("Sheet4").Cells(i, j).Value = Sheets("Sheet2").Cells(i, j).Value 'CStr("MisMatch") 'If mismatch setting set value as MisMatch
Sheets("Sheet4").Cells(i, j).Interior.Color = 65535 'Highlighting with Yellow color
Else
Sheets("Sheet4").Cells(i, j).Value = Sheets("Sheet2").Cells(i, j).Value
'If values are same copy the first sheets value if dont want to copy can skip this
End If

Next
Next
MsgBox "SORTINGCOMPLETE"
End Sub









share|improve this question
























  • Don't tag spam.

    – shmosel
    Nov 16 '18 at 3:28













0












0








0








I have 2 sheets with one offline data and one online data from a DB server and want to sort the difference between the two sheets and highlight the difference and count the difference and display the counting value in the end column if its there else have to say "same" in the end column.
For eg: Sheet 1



 A B C D 
T1 T2 T3 T4
T1 T2 T3 T4


Sheet 2



 A B C D 
T1 T2 T3 T4
T1 T2 T4 T5


Result--> sheet 3 should be



 A B C D E 
T1 T2 T3 T4
T1 T2 T3 T4 Same
T1 T2 T3 T4
T1 T2 T4 T5 2 difference


The Code i have is highlighting the difference but not Pasting the Sheet 1 value in the Sheet 3.My end result will be comparing the Same row and cell between the Sheet1 snd Sheet2 and have to paste the difference in the sheet 3 with pasting both rows consecutively. Any help is highly appreciated.



Sub Compare()
Dim ColumnCount, RowCount As Long
Dim w As Worksheet, r As Range

'Clearing the contents of the third sheet for the fresh comparison

usedCoulms = ThisWorkbook.Worksheets("Sheet4").UsedRange.Columns.Count
usedRows = ThisWorkbook.Worksheets("Sheet4").UsedRange.Rows.Count
For i = 1 To usedRows
For j = 1 To usedCoulms
Sheets("Sheet4").Cells(i, j).Value = ""
Sheets("Sheet4").Cells(i, j).Interior.Color = RGB(255, 255, 255)
Next
Next

'Coulmn count of first sheet
ColumnCount = ThisWorkbook.Worksheets("Sheet1").UsedRange.Columns.Count
'row count of first sheet
RowCount = ThisWorkbook.Worksheets("Sheet1").UsedRange.Rows.Count

For i = 1 To RowCount

For j = 1 To ColumnCount
If Sheets("Sheet1").Cells(i, j).Value <> Sheets("Sheet2").Cells(i, j).Value Then 'Comparing if values are not equal
Sheets("Sheet4").Cells(i, j).Value = Sheets("Sheet1").Cells(i, j).Value 'Copying the Header of the Mismatched Cell
Sheets("Sheet4").Cells(i, j).Value = Sheets("Sheet2").Cells(i, j).Value 'CStr("MisMatch") 'If mismatch setting set value as MisMatch
Sheets("Sheet4").Cells(i, j).Interior.Color = 65535 'Highlighting with Yellow color
Else
Sheets("Sheet4").Cells(i, j).Value = Sheets("Sheet2").Cells(i, j).Value
'If values are same copy the first sheets value if dont want to copy can skip this
End If

Next
Next
MsgBox "SORTINGCOMPLETE"
End Sub









share|improve this question
















I have 2 sheets with one offline data and one online data from a DB server and want to sort the difference between the two sheets and highlight the difference and count the difference and display the counting value in the end column if its there else have to say "same" in the end column.
For eg: Sheet 1



 A B C D 
T1 T2 T3 T4
T1 T2 T3 T4


Sheet 2



 A B C D 
T1 T2 T3 T4
T1 T2 T4 T5


Result--> sheet 3 should be



 A B C D E 
T1 T2 T3 T4
T1 T2 T3 T4 Same
T1 T2 T3 T4
T1 T2 T4 T5 2 difference


The Code i have is highlighting the difference but not Pasting the Sheet 1 value in the Sheet 3.My end result will be comparing the Same row and cell between the Sheet1 snd Sheet2 and have to paste the difference in the sheet 3 with pasting both rows consecutively. Any help is highly appreciated.



Sub Compare()
Dim ColumnCount, RowCount As Long
Dim w As Worksheet, r As Range

'Clearing the contents of the third sheet for the fresh comparison

usedCoulms = ThisWorkbook.Worksheets("Sheet4").UsedRange.Columns.Count
usedRows = ThisWorkbook.Worksheets("Sheet4").UsedRange.Rows.Count
For i = 1 To usedRows
For j = 1 To usedCoulms
Sheets("Sheet4").Cells(i, j).Value = ""
Sheets("Sheet4").Cells(i, j).Interior.Color = RGB(255, 255, 255)
Next
Next

'Coulmn count of first sheet
ColumnCount = ThisWorkbook.Worksheets("Sheet1").UsedRange.Columns.Count
'row count of first sheet
RowCount = ThisWorkbook.Worksheets("Sheet1").UsedRange.Rows.Count

For i = 1 To RowCount

For j = 1 To ColumnCount
If Sheets("Sheet1").Cells(i, j).Value <> Sheets("Sheet2").Cells(i, j).Value Then 'Comparing if values are not equal
Sheets("Sheet4").Cells(i, j).Value = Sheets("Sheet1").Cells(i, j).Value 'Copying the Header of the Mismatched Cell
Sheets("Sheet4").Cells(i, j).Value = Sheets("Sheet2").Cells(i, j).Value 'CStr("MisMatch") 'If mismatch setting set value as MisMatch
Sheets("Sheet4").Cells(i, j).Interior.Color = 65535 'Highlighting with Yellow color
Else
Sheets("Sheet4").Cells(i, j).Value = Sheets("Sheet2").Cells(i, j).Value
'If values are same copy the first sheets value if dont want to copy can skip this
End If

Next
Next
MsgBox "SORTINGCOMPLETE"
End Sub






excel vba excel-vba ms-access access-vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 10:59









Pᴇʜ

24.1k63052




24.1k63052










asked Nov 16 '18 at 1:20









CHANCHAN

11




11












  • Don't tag spam.

    – shmosel
    Nov 16 '18 at 3:28

















  • Don't tag spam.

    – shmosel
    Nov 16 '18 at 3:28
















Don't tag spam.

– shmosel
Nov 16 '18 at 3:28





Don't tag spam.

– shmosel
Nov 16 '18 at 3:28












1 Answer
1






active

oldest

votes


















0














I think it would be better and easier to have all data in same sheet, because you are comparing always same rows of both sheets. So I did this:



enter image description here



You compare row 2 of Sheet1 with row 2 of Sheet2, row3 with row 3, and so on...



Then,in the evaluation column, I have this formula:



=IF(4-SUMPRODUCT(--(A2:D2=F2:I2))>0;4-SUMPRODUCT(--(A2:D2=F2:I2))&" difference";"same")


As you can see, first comparison returns same because there are no differences. Second comparison (row 3) returns 2 difference because there is only 2 matches.



To highlight the evaluation, just a conditional formatting rule. If the text contains the word difference, highlit it.



Hope you can adap this to your needs.






share|improve this answer























  • Thanks Foxfire..Got it fixed and thanks for helping

    – CHAN
    Jan 16 at 3:36










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330132%2fchecking-the-difference-between-2-sheets-and-highlight-the-difference-with-the-c%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I think it would be better and easier to have all data in same sheet, because you are comparing always same rows of both sheets. So I did this:



enter image description here



You compare row 2 of Sheet1 with row 2 of Sheet2, row3 with row 3, and so on...



Then,in the evaluation column, I have this formula:



=IF(4-SUMPRODUCT(--(A2:D2=F2:I2))>0;4-SUMPRODUCT(--(A2:D2=F2:I2))&" difference";"same")


As you can see, first comparison returns same because there are no differences. Second comparison (row 3) returns 2 difference because there is only 2 matches.



To highlight the evaluation, just a conditional formatting rule. If the text contains the word difference, highlit it.



Hope you can adap this to your needs.






share|improve this answer























  • Thanks Foxfire..Got it fixed and thanks for helping

    – CHAN
    Jan 16 at 3:36















0














I think it would be better and easier to have all data in same sheet, because you are comparing always same rows of both sheets. So I did this:



enter image description here



You compare row 2 of Sheet1 with row 2 of Sheet2, row3 with row 3, and so on...



Then,in the evaluation column, I have this formula:



=IF(4-SUMPRODUCT(--(A2:D2=F2:I2))>0;4-SUMPRODUCT(--(A2:D2=F2:I2))&" difference";"same")


As you can see, first comparison returns same because there are no differences. Second comparison (row 3) returns 2 difference because there is only 2 matches.



To highlight the evaluation, just a conditional formatting rule. If the text contains the word difference, highlit it.



Hope you can adap this to your needs.






share|improve this answer























  • Thanks Foxfire..Got it fixed and thanks for helping

    – CHAN
    Jan 16 at 3:36













0












0








0







I think it would be better and easier to have all data in same sheet, because you are comparing always same rows of both sheets. So I did this:



enter image description here



You compare row 2 of Sheet1 with row 2 of Sheet2, row3 with row 3, and so on...



Then,in the evaluation column, I have this formula:



=IF(4-SUMPRODUCT(--(A2:D2=F2:I2))>0;4-SUMPRODUCT(--(A2:D2=F2:I2))&" difference";"same")


As you can see, first comparison returns same because there are no differences. Second comparison (row 3) returns 2 difference because there is only 2 matches.



To highlight the evaluation, just a conditional formatting rule. If the text contains the word difference, highlit it.



Hope you can adap this to your needs.






share|improve this answer













I think it would be better and easier to have all data in same sheet, because you are comparing always same rows of both sheets. So I did this:



enter image description here



You compare row 2 of Sheet1 with row 2 of Sheet2, row3 with row 3, and so on...



Then,in the evaluation column, I have this formula:



=IF(4-SUMPRODUCT(--(A2:D2=F2:I2))>0;4-SUMPRODUCT(--(A2:D2=F2:I2))&" difference";"same")


As you can see, first comparison returns same because there are no differences. Second comparison (row 3) returns 2 difference because there is only 2 matches.



To highlight the evaluation, just a conditional formatting rule. If the text contains the word difference, highlit it.



Hope you can adap this to your needs.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 14 at 13:24









Foxfire And Burns And BurnsFoxfire And Burns And Burns

2,0731518




2,0731518












  • Thanks Foxfire..Got it fixed and thanks for helping

    – CHAN
    Jan 16 at 3:36

















  • Thanks Foxfire..Got it fixed and thanks for helping

    – CHAN
    Jan 16 at 3:36
















Thanks Foxfire..Got it fixed and thanks for helping

– CHAN
Jan 16 at 3:36





Thanks Foxfire..Got it fixed and thanks for helping

– CHAN
Jan 16 at 3:36



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330132%2fchecking-the-difference-between-2-sheets-and-highlight-the-difference-with-the-c%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線