How to compare two range of cells in two different excel Worksheets?












2















I've put my vba code here to show you my progress so far on the subject. This is intended to be a macro which activates on a commandbutton click.



Thank you for your suggestions, unfortunately I don't see if that flagged duplicate would solve my problem. I will try to clarify it the best as i can. In each Worksheets, in the same range there are two identical 9*9 width and height block of cells, and each cell is filled with a single number from 1 to 9 value. The values of the cells are identical too in both worksheets. What I would expect from my code to do is to compare the two ranges's each value in each cell, and if all of them are a match, write in msgbox success, else fail. I tried writing .Value after defining each range, but that doesn't work either.



I always get a runtime error 13: type mismatch. I was guessing this type of problem is related to that my values are not the same type, but I only have numbers in each declared range. I've googled the problem, but since i can't seem to figure out the root of this problem, I'm hoping You can be an answer to my dilemma.



Sub Check()    
If Sheets("Sudoku").Range("B2:J10") = Sheets("Solution").Range("B2:J10") Then
MsgBox "Success!"
Else
MsgBox "Fail!"
End If
End Sub


Any kind of answer would be greatly appreciated!
Thank you all for the answers, We finally came up with a solution! I'll put it below if anyone is interested in it. It is a slightly modified version of Odatas's version.



Sub Check()
Dim i As Integer
Dim j As Integer

For i = 2 To Sheets("Sudoku").Cells(Sheets("Sudoku").Rows.Count, "B").End(xlUp).Row
For j = 2 To Sheets("Sudoku").Cells(2, Sheets("Sudoku").Columns.Count).End(xlToLeft).Column
If Sheets("Sudoku").Cells(j, i).Value = Sheets("Megoldás").Cells(j, i).Value Then
Else
MsgBox ("Fail!")
Exit Sub
End If
Next
Next
MsgBox ("Success!")

End Sub









share|improve this question

























  • What property of the range are you trying to compare? And what problem arises with your code? If it is the .Value property, you need to check each cell individually. If it is something else, then clarify your question.

    – Ron Rosenfeld
    Nov 26 '18 at 11:07








  • 1





    Possible duplicate of Fastest way to check if two ranges are equal in excel vba

    – Pragmateek
    Nov 26 '18 at 11:09
















2















I've put my vba code here to show you my progress so far on the subject. This is intended to be a macro which activates on a commandbutton click.



Thank you for your suggestions, unfortunately I don't see if that flagged duplicate would solve my problem. I will try to clarify it the best as i can. In each Worksheets, in the same range there are two identical 9*9 width and height block of cells, and each cell is filled with a single number from 1 to 9 value. The values of the cells are identical too in both worksheets. What I would expect from my code to do is to compare the two ranges's each value in each cell, and if all of them are a match, write in msgbox success, else fail. I tried writing .Value after defining each range, but that doesn't work either.



I always get a runtime error 13: type mismatch. I was guessing this type of problem is related to that my values are not the same type, but I only have numbers in each declared range. I've googled the problem, but since i can't seem to figure out the root of this problem, I'm hoping You can be an answer to my dilemma.



Sub Check()    
If Sheets("Sudoku").Range("B2:J10") = Sheets("Solution").Range("B2:J10") Then
MsgBox "Success!"
Else
MsgBox "Fail!"
End If
End Sub


Any kind of answer would be greatly appreciated!
Thank you all for the answers, We finally came up with a solution! I'll put it below if anyone is interested in it. It is a slightly modified version of Odatas's version.



Sub Check()
Dim i As Integer
Dim j As Integer

For i = 2 To Sheets("Sudoku").Cells(Sheets("Sudoku").Rows.Count, "B").End(xlUp).Row
For j = 2 To Sheets("Sudoku").Cells(2, Sheets("Sudoku").Columns.Count).End(xlToLeft).Column
If Sheets("Sudoku").Cells(j, i).Value = Sheets("Megoldás").Cells(j, i).Value Then
Else
MsgBox ("Fail!")
Exit Sub
End If
Next
Next
MsgBox ("Success!")

End Sub









share|improve this question

























  • What property of the range are you trying to compare? And what problem arises with your code? If it is the .Value property, you need to check each cell individually. If it is something else, then clarify your question.

    – Ron Rosenfeld
    Nov 26 '18 at 11:07








  • 1





    Possible duplicate of Fastest way to check if two ranges are equal in excel vba

    – Pragmateek
    Nov 26 '18 at 11:09














2












2








2








I've put my vba code here to show you my progress so far on the subject. This is intended to be a macro which activates on a commandbutton click.



Thank you for your suggestions, unfortunately I don't see if that flagged duplicate would solve my problem. I will try to clarify it the best as i can. In each Worksheets, in the same range there are two identical 9*9 width and height block of cells, and each cell is filled with a single number from 1 to 9 value. The values of the cells are identical too in both worksheets. What I would expect from my code to do is to compare the two ranges's each value in each cell, and if all of them are a match, write in msgbox success, else fail. I tried writing .Value after defining each range, but that doesn't work either.



I always get a runtime error 13: type mismatch. I was guessing this type of problem is related to that my values are not the same type, but I only have numbers in each declared range. I've googled the problem, but since i can't seem to figure out the root of this problem, I'm hoping You can be an answer to my dilemma.



Sub Check()    
If Sheets("Sudoku").Range("B2:J10") = Sheets("Solution").Range("B2:J10") Then
MsgBox "Success!"
Else
MsgBox "Fail!"
End If
End Sub


Any kind of answer would be greatly appreciated!
Thank you all for the answers, We finally came up with a solution! I'll put it below if anyone is interested in it. It is a slightly modified version of Odatas's version.



Sub Check()
Dim i As Integer
Dim j As Integer

For i = 2 To Sheets("Sudoku").Cells(Sheets("Sudoku").Rows.Count, "B").End(xlUp).Row
For j = 2 To Sheets("Sudoku").Cells(2, Sheets("Sudoku").Columns.Count).End(xlToLeft).Column
If Sheets("Sudoku").Cells(j, i).Value = Sheets("Megoldás").Cells(j, i).Value Then
Else
MsgBox ("Fail!")
Exit Sub
End If
Next
Next
MsgBox ("Success!")

End Sub









share|improve this question
















I've put my vba code here to show you my progress so far on the subject. This is intended to be a macro which activates on a commandbutton click.



Thank you for your suggestions, unfortunately I don't see if that flagged duplicate would solve my problem. I will try to clarify it the best as i can. In each Worksheets, in the same range there are two identical 9*9 width and height block of cells, and each cell is filled with a single number from 1 to 9 value. The values of the cells are identical too in both worksheets. What I would expect from my code to do is to compare the two ranges's each value in each cell, and if all of them are a match, write in msgbox success, else fail. I tried writing .Value after defining each range, but that doesn't work either.



I always get a runtime error 13: type mismatch. I was guessing this type of problem is related to that my values are not the same type, but I only have numbers in each declared range. I've googled the problem, but since i can't seem to figure out the root of this problem, I'm hoping You can be an answer to my dilemma.



Sub Check()    
If Sheets("Sudoku").Range("B2:J10") = Sheets("Solution").Range("B2:J10") Then
MsgBox "Success!"
Else
MsgBox "Fail!"
End If
End Sub


Any kind of answer would be greatly appreciated!
Thank you all for the answers, We finally came up with a solution! I'll put it below if anyone is interested in it. It is a slightly modified version of Odatas's version.



Sub Check()
Dim i As Integer
Dim j As Integer

For i = 2 To Sheets("Sudoku").Cells(Sheets("Sudoku").Rows.Count, "B").End(xlUp).Row
For j = 2 To Sheets("Sudoku").Cells(2, Sheets("Sudoku").Columns.Count).End(xlToLeft).Column
If Sheets("Sudoku").Cells(j, i).Value = Sheets("Megoldás").Cells(j, i).Value Then
Else
MsgBox ("Fail!")
Exit Sub
End If
Next
Next
MsgBox ("Success!")

End Sub






excel vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 15:43







Devilhunter

















asked Nov 26 '18 at 10:59









DevilhunterDevilhunter

244




244













  • What property of the range are you trying to compare? And what problem arises with your code? If it is the .Value property, you need to check each cell individually. If it is something else, then clarify your question.

    – Ron Rosenfeld
    Nov 26 '18 at 11:07








  • 1





    Possible duplicate of Fastest way to check if two ranges are equal in excel vba

    – Pragmateek
    Nov 26 '18 at 11:09



















  • What property of the range are you trying to compare? And what problem arises with your code? If it is the .Value property, you need to check each cell individually. If it is something else, then clarify your question.

    – Ron Rosenfeld
    Nov 26 '18 at 11:07








  • 1





    Possible duplicate of Fastest way to check if two ranges are equal in excel vba

    – Pragmateek
    Nov 26 '18 at 11:09

















What property of the range are you trying to compare? And what problem arises with your code? If it is the .Value property, you need to check each cell individually. If it is something else, then clarify your question.

– Ron Rosenfeld
Nov 26 '18 at 11:07







What property of the range are you trying to compare? And what problem arises with your code? If it is the .Value property, you need to check each cell individually. If it is something else, then clarify your question.

– Ron Rosenfeld
Nov 26 '18 at 11:07






1




1





Possible duplicate of Fastest way to check if two ranges are equal in excel vba

– Pragmateek
Nov 26 '18 at 11:09





Possible duplicate of Fastest way to check if two ranges are equal in excel vba

– Pragmateek
Nov 26 '18 at 11:09












1 Answer
1






active

oldest

votes


















0














You need to iterate through all values.



    Sub Check()
Dim i As Integer
Dim j As Integer


For i = 1 To Sheets("Sudoku").Cells(.Rows.Count, "A").End(xlUp).Row
for j= 1 to Sheets("Sudoku")..Cells(1, .Columns.Count).End(xlToLeft).Column
If Sheets("Sudoku").Cells(j, i).value = Sheets("Solution").Cells(j, i).value Then

Else If
MsgBox("Fail")
Exit Sub
End If

Next
Next

MsgBox("Success")
End Sub





share|improve this answer



















  • 1





    Thank you! This solution with slight modifications worked! I'll update the thread according to this, and put the working code in if anyone else wonders how to do it.

    – Devilhunter
    Nov 26 '18 at 15:38












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%2f53479669%2fhow-to-compare-two-range-of-cells-in-two-different-excel-worksheets%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














You need to iterate through all values.



    Sub Check()
Dim i As Integer
Dim j As Integer


For i = 1 To Sheets("Sudoku").Cells(.Rows.Count, "A").End(xlUp).Row
for j= 1 to Sheets("Sudoku")..Cells(1, .Columns.Count).End(xlToLeft).Column
If Sheets("Sudoku").Cells(j, i).value = Sheets("Solution").Cells(j, i).value Then

Else If
MsgBox("Fail")
Exit Sub
End If

Next
Next

MsgBox("Success")
End Sub





share|improve this answer



















  • 1





    Thank you! This solution with slight modifications worked! I'll update the thread according to this, and put the working code in if anyone else wonders how to do it.

    – Devilhunter
    Nov 26 '18 at 15:38
















0














You need to iterate through all values.



    Sub Check()
Dim i As Integer
Dim j As Integer


For i = 1 To Sheets("Sudoku").Cells(.Rows.Count, "A").End(xlUp).Row
for j= 1 to Sheets("Sudoku")..Cells(1, .Columns.Count).End(xlToLeft).Column
If Sheets("Sudoku").Cells(j, i).value = Sheets("Solution").Cells(j, i).value Then

Else If
MsgBox("Fail")
Exit Sub
End If

Next
Next

MsgBox("Success")
End Sub





share|improve this answer



















  • 1





    Thank you! This solution with slight modifications worked! I'll update the thread according to this, and put the working code in if anyone else wonders how to do it.

    – Devilhunter
    Nov 26 '18 at 15:38














0












0








0







You need to iterate through all values.



    Sub Check()
Dim i As Integer
Dim j As Integer


For i = 1 To Sheets("Sudoku").Cells(.Rows.Count, "A").End(xlUp).Row
for j= 1 to Sheets("Sudoku")..Cells(1, .Columns.Count).End(xlToLeft).Column
If Sheets("Sudoku").Cells(j, i).value = Sheets("Solution").Cells(j, i).value Then

Else If
MsgBox("Fail")
Exit Sub
End If

Next
Next

MsgBox("Success")
End Sub





share|improve this answer













You need to iterate through all values.



    Sub Check()
Dim i As Integer
Dim j As Integer


For i = 1 To Sheets("Sudoku").Cells(.Rows.Count, "A").End(xlUp).Row
for j= 1 to Sheets("Sudoku")..Cells(1, .Columns.Count).End(xlToLeft).Column
If Sheets("Sudoku").Cells(j, i).value = Sheets("Solution").Cells(j, i).value Then

Else If
MsgBox("Fail")
Exit Sub
End If

Next
Next

MsgBox("Success")
End Sub






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 26 '18 at 14:12









OdatasOdatas

427




427








  • 1





    Thank you! This solution with slight modifications worked! I'll update the thread according to this, and put the working code in if anyone else wonders how to do it.

    – Devilhunter
    Nov 26 '18 at 15:38














  • 1





    Thank you! This solution with slight modifications worked! I'll update the thread according to this, and put the working code in if anyone else wonders how to do it.

    – Devilhunter
    Nov 26 '18 at 15:38








1




1





Thank you! This solution with slight modifications worked! I'll update the thread according to this, and put the working code in if anyone else wonders how to do it.

– Devilhunter
Nov 26 '18 at 15:38





Thank you! This solution with slight modifications worked! I'll update the thread according to this, and put the working code in if anyone else wonders how to do it.

– Devilhunter
Nov 26 '18 at 15:38




















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%2f53479669%2fhow-to-compare-two-range-of-cells-in-two-different-excel-worksheets%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

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen