I find the easiest way to handle dynamic ranges is to use tables. Put your cash flows in one column, and then the dates in the column next to the cash flows. Highlight one of the cells and hit Ctrl-T. This will generate a table.

For your xnpv calculation, you should use the table references for the ranges. You will get something like this:
=XNPV(0.05,Table1[Column1],Table1[Column2])

Now you can add or remove rows to the table and the xnpv formula should always adjust.