A great learning tool is recording macros and this seems like a perfect candidate for it.
Just type in the formula you want in cell D2, go to View > Macros > Record Macro, and then just use the autofill (double click on bottom right of the box of the you just typed in). Then stop recording and look to see what the macro says.
If you want it to be able to run multiple times with different lengths of data you will need to probably build in something (or record) to clear out the cells that are there.
This is what I got when doing a very simple recording. You can then edit it afterward to include anything it is not doing
Then you just need to right click on your button and goto Assign Macro and choose the macro you just recorded.
Bookmarks