Checking the Difference between 2 sheets and highlight the difference with the column saying...
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
add a comment |
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
Don't tag spam.
– shmosel
Nov 16 '18 at 3:28
add a comment |
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
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
excel vba excel-vba ms-access access-vba
edited Nov 16 '18 at 10:59
Pᴇʜ
24.6k63052
24.6k63052
asked Nov 16 '18 at 1:20
CHANCHAN
11
11
Don't tag spam.
– shmosel
Nov 16 '18 at 3:28
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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:
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.
Thanks Foxfire..Got it fixed and thanks for helping
– CHAN
Jan 16 at 3:36
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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:
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.
Thanks Foxfire..Got it fixed and thanks for helping
– CHAN
Jan 16 at 3:36
add a comment |
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:
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.
Thanks Foxfire..Got it fixed and thanks for helping
– CHAN
Jan 16 at 3:36
add a comment |
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:
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.
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:
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.
answered Jan 14 at 13:24
Foxfire And Burns And BurnsFoxfire And Burns And Burns
2,0791518
2,0791518
Thanks Foxfire..Got it fixed and thanks for helping
– CHAN
Jan 16 at 3:36
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Don't tag spam.
– shmosel
Nov 16 '18 at 3:28