You can do this with a pair of macros. One "searching" macro to determine when you need to insert a new row and one "processing" macro to do the work.
Developing the processing macro is easy. Create a spreadsheet with your sample data. Sort it on the three key columns. Then record a macro and manually perform all the processing steps:
- Insert a new row at the desired location.
- Copy the existing row to the new one.
- Set the desired cell to 0
This macro will have hard-coded cell references which you will need to replace with references provided by the searching macro
While you will need to build the searching macro from scratch, the processing is not complicated.
- Sort the data on the three key columns
- Starting a row 2, loop through the rows.
- If the three key cells do not match the cells in the previous row, invoke the processing macro for this row and then skip one row
- Repeat for next row.
- Sort the data back to original order if necessary