Avatar of Magpie Bavarde
Magpie Bavarde
Flag for France

asked on 

VBA : compare 2 columns and complete the shortest one

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 

Open in new window

... 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 !
VBAMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Flyster

8/22/2022 - Mon