Excel doesn't automatically reset the used range until the workbook is saved.
This is untested but you might get a reset on the fly with
one of these two instructions right ahead of putting in the boarders and fonts.
Code:
ActiveSheet.UsedRange
X = ActiveSheet.UsedRange.Rows.Count
'Put borders around new rows.