VBA code to Compare column A of two sheets and insert rows for missing numbers on sheet 2

Curtisyoung78

New Member
Joined
Jun 19, 2017
Messages
25
Hello again guys, I need your help with some vba coding That will compare Column A on sheet 1 and 2 which is a Pile Schedule (sheets are revisions), listing pile numbers in cloumn A, if a pile is not included on sheet 2 (Has Been Deleted) then I need it to insert a row where the missing pile number would be and show that pile number in column A, then add "-" in cells B thru K, P & Q and "NOT USED" in column L.

Just need this so that sheet 1 and 2 have the same numbers in column A when i run a macro that compares both sheets to bold the differences in cells. If the piles that have been deleted are not included on sheet 2 then all piles after them would be bolded. I bold the cells that have changed between revisions to have them stand out.

Thanks in advance.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try this
Code:
Sub FindMissing()

    Dim Cnt As Long
    Dim Sht1 As Worksheet
    Dim Sht2 As Worksheet
    
    Set Sht1 = Sheets("Summary")
    Set Sht2 = Sheets("Test1")
    
    For Cnt = 2 To Sht1.Range("A" & Rows.Count).End(xlUp).Row
        If Sht1.Range("A" & Cnt).Value <> Sht2.Range("A" & Cnt) Then
            Sht2.Rows(Cnt).Insert
            Sht2.Range("A" & Cnt).Value = Sht1.Range("A" & Cnt).Value
            Sht2.Range("B" & Cnt).Resize(, 10).Value = "-"
            Sht2.Range("L" & Cnt).Value = "NOT USED"
            Sht2.Range("P" & Cnt).Resize(, 2).Value = "-"
        End If
    Next Cnt

End Sub
 
Upvote 0
Thanks Fluff, it works but i forgot to mention that it needs to work from row 12 down, Sorry. Can you tweek it to work from row 12 down to the end. I tried a few things but my VBA skills are to limited. Thanks in advance.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0
Fluff:

I there a way to modify the code to skip items in the master list, if they are not In the list your comparing to?
I use the code but seem to be running into an issue, as I have a master list and if I run the VBA I will insert all rows if the item is on the master instead of skipping if not located
 
Upvote 0
As the code was designed to do that, your question is different, so please start a new thread.
 
Upvote 0

Forum statistics

Threads
1,223,714
Messages
6,174,051
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top