troubleshooting Question

VBA : compare 2 columns and complete the shortest one

Avatar of Magpie Bavarde
Magpie BavardeFlag for France asked on
VBAMicrosoft ExcelMicrosoft Office
5 Comments1 Solution62 ViewsLast Modified:
Hello the experts,

I want a generic code that will work on several very different sheets. One of them ("Full") has more data than the other ("Miss"). So far I have this from internet and switch a little to get closer to my goal. That part does half of the job (compare then add an empty row) :
 Sub WIPInsertMissing()
    Dim lastrow As Long, i As Long, j As Long
    lastrow = Sheets("Full").Range("A" & Rows.Count).End(xlUp).row
        j = 1
    For i = 1 To lastrow
        If Sheets("Miss").Cells(j, 1).Value <> Sheets("Full").Cells(i, 1).Value Then
            Sheets("Miss").Rows(j).Insert Shift:=xlDown
        End If
        j = j + 1
    Next i
End Sub 
... but it doesnt always work and I can't figure why. I wouldnt mind some help to correct the code and add the part where it copies the missing data ;) to get something like this : FillsMissingMacro.png
I thank you very much for your help !
ASKER CERTIFIED SOLUTION
Flyster

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros