Yeah, 27 rows are added. How'd you know that???
Unfortunately, starting from the bottom won't work because the first set of data (after deleting out prior month records) is still over 100 records longer than the second set of data.
What I tried, since there are so many prior month records being deleted, was to NOT reset the strLastRow after the prior month records are deleted. This worked with this data set, but I don't know if the next data set will delete more prior period records than it adds. Here is the modified code. I've remarked out two lines of code.
Any idea why it stoped at 13840? Thanks again for all your suggestions.
<font face=Courier New><SPAN style="color:#007F00">' DECLARATION OF VARIABLES</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> strLastDay <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN> <SPAN style="color:#007F00">'last day of previous month</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> strLastRow1 <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN> <SPAN style="color:#007F00">'last row row number</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> strLastRow2 <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN> <SPAN style="color:#007F00">'last row row number</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> h <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>
Sheets("Sheet 2").Activate
Range("B6").Select
<SPAN style="color:#007F00">'user to imput the last day of previous month to delete records</SPAN>
strLastDay = InputBox("Enter the Last Day of the Previous Month" & _
"(mmddyy format), then press OK or ENTER", "Last day of the previous month", _
"103104")
<SPAN style="color:#007F00">'delete last months records</SPAN>
strLastRow1 = Range("B65536").End(xlUp).Row
<SPAN style="color:#00007F">For</SPAN> h = strLastRow1 <SPAN style="color:#00007F">To</SPAN> 6 <SPAN style="color:#00007F">Step</SPAN> -1
<SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">Resume</SPAN> <SPAN style="color:#00007F">Next</SPAN>
<SPAN style="color:#00007F">If</SPAN> Cells(h, 3) = strLastDay <SPAN style="color:#00007F">Then</SPAN>
Range("B" & h, "F" & h).Select
Selection.Delete Shift:=xlUp
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">Next</SPAN> h
<SPAN style="color:#007F00">'*** strLastRow1 = Range("B65536").End(xlUp).Row</SPAN>
Range("B6").Select
<SPAN style="color:#007F00">'Comparison Loop</SPAN>
<SPAN style="color:#00007F">For</SPAN> i = 6 <SPAN style="color:#00007F">To</SPAN> strLastRow1
<SPAN style="color:#00007F">If</SPAN> Cells(i, "E") = Cells(i, "I") <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> Skip
<SPAN style="color:#00007F">If</SPAN> Cells(i, "E") = Cells(i + 1, "I") <SPAN style="color:#00007F">Then</SPAN>
Range("B" & i, "F" & i).Select
Selection.Insert Shift:=xlDown
<SPAN style="color:#00007F">GoTo</SPAN> Skip
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">If</SPAN> Cells(i + 1, "E") = Cells(i, "I") <SPAN style="color:#00007F">Then</SPAN>
Range("G" & i, "J" & i).Select
Selection.Insert Shift:=xlDown
<SPAN style="color:#00007F">GoTo</SPAN> Skip
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">If</SPAN> Cells(i, "E") = Cells(i + 2, "I") <SPAN style="color:#00007F">Then</SPAN>
Range("B" & i, "F" & i).Select
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown
<SPAN style="color:#00007F">GoTo</SPAN> Skip
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">If</SPAN> Cells(i + 2, "E") = Cells(i, "I") <SPAN style="color:#00007F">Then</SPAN>
Range("G" & i, "J" & i).Select
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown
<SPAN style="color:#00007F">GoTo</SPAN> Skip
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
Skip:
<SPAN style="color:#007F00">'*** strLastRow1 = Range("B65536").End(xlUp).Row</SPAN>
<SPAN style="color:#00007F">Next</SPAN> i
<SPAN style="color:#007F00">'Add Variance Column</SPAN>
strLastRow2 = Range("G65536").End(xlUp).Row
Range("K6").Select
ActiveCell.FormulaR1C1 = "=RC[-6]-RC[-2]"
ActiveCell.Copy
Range("K6:K" & strLastRow2).Select
ActiveSheet.Paste
Application.CutCopyMode = <SPAN style="color:#00007F">False</SPAN>
Range("B6").Select
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>