EXCEL VBA to Compare WS and insert missing data.

torrino1

New Member
Joined
May 1, 2018
Messages
5
I have the following code to compare two worksheets and if any of the account data is missing insert a row to add the missing data. When I ran the Macro it worked as expected accept it did the insert piece for every number after the first in the list that was not present on the compared master list. Any suggestions on how to ensure that only the missing account data is inserted as opposed to all subsequent rows in the comparative sheet?

Dim Cnt As Long
Dim Sht1 As Worksheet
Dim Sht2 As Worksheet

Set Sht1 = Sheets("Execute Billing")
Set Sht2 = Sheets("Account Master File")

For Cnt = 2 To Sht1.Range("A" & Rows.Count).End(xlUp).Row
If Sht2.Range("A" & Cnt).Value <> Sht1.Range("A" & Cnt) Then
Sht2.Rows(Cnt).Insert
Sht2.Range("A" & Cnt).Value = Sht1.Range("A" & Cnt).Value
Selection.NumberFormat = "000000000000000"
Sht2.Range("B" & Cnt).Value = Sht1.Range("C" & Cnt).Value
Sht2.Range("C" & Cnt).Value = "NEW"
Sht2.Range("D" & Cnt).FormulaR1C1 = "=SUM(RC[-1]*5+18)"
Sht2.Range("E" & Cnt).FormulaR1C1 = "=RC[4]&TEXT(RC[-4],""000000000000000"")&RC[5]"
Sht2.Range("F" & Cnt).FormulaR1C1 = "=SUM(RC[-2]*100)"
Sht2.Range("H" & Cnt).FormulaR1C1 = "=RC[-3]&TEXT(RC[-2],""0000000000000"")"
Sht2.Range("I" & Cnt).Value = "'001"
Sht2.Range("J" & Cnt).Value = "'0125"

Any guidance/assistance would be appreciated, and please excuse any posting etiquette miss-steps as this is my first post.
Thanks in advance.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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