If there is any row that is unmerged in the last section, it creates an issue for the macro.

Can we fix on a particular row count for the last section? For e.g. can we say that if the number of allotted rows for Action is 10 and the no of entries is 11, then the macro needs to insert a row and put the value in.

If not, you just have to ensure that the required rows in each section (specially Action) are merged before you run the macro.