The range for merge_range() does not have to be hard-coded.
If you can derive the value 51 from your data, then you can create the first argument of merge_range() dynamically and pass that to the method.
$range = "A".$last_col.":G".$last_col; # $last_col = 51
$worksheet1->merge_range($range, "New data to be pasted here", $format10);