|As far as I can tell, this is the problem line:|
Set findRw = .Find(Sheets(1).Cells(srcRw, "B"), LookIn:=xlValues)
As explained at the following site, the Find feature within Excel and the .Find method in VBA are interconnected:
I'll quote the relevant paragraph, but you should review the other information available at that site:
The settings for LookIn, LookAt, SearchOrder, and MatchByte are saved each time you use this method. If you do not specify values for these arguments the next time you call the method, the saved values are used. Setting these arguments changes the settings in the Find dialog box, and changing the settings in the Find dialog box changes the saved values that are used if you omit the arguments. To avoid problems, set these arguments explicitly each time you use this method.
My guess is that on your system the current setting for the LookAt argument is xlPart. The way to verify this would be to go into your spreadsheet, open the Find dialog box and see if the "Check entire cell contents" box is checked. My guess is that it is not.
What is happening in the case of adding a ID number 10 is that the code is finding a single instance of 10 on Sheet2, but 2 instances of 1 (1 and 10). This is because the code is not checking the entire cell contents as as single value (xlWhole) but is checking for partial values (xlPart).
When you add ID numbers 11 and 12, things get even worse because the code is now finding 4 instances of 1 (1, 10, 11 and 12), 2 instances of 2 (2 and 12), etc. Once the code starts adding rows when it shouldn't, the deletion section is going to get messed up as well.
The fix, as stated in the paragraph I quoted above, is to explicitly set that option in the code. I don't always do that, perhaps I should start to always do that in the future.
Set findRw = .Find(Sheets(1).Cells(srcRw, "B"), _
Once you run the code with that line, not only should the code work, but if you go back into the Find dialog box in Excel, you should find that the "Check entire cell contents" box is now checked. Even if it gets manually unchecked in the future, the code will change the check box it each time it is run because you have explicitly set it via the LookAt argument.
Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.