If it will works correctly, does what you intended, then yes - “this is correct”.
Perhaps someone will criticize this approach and call such a decision stupid - what do you care about the opinion of critics?
Yes, there is such a way. The problem is that, as always in programming, there are several such paths - it is difficult to choose the “correct” one (they are all “correct” and each of them has flaws)
For example, you can list the addresses of all processed ranges in an array and loop through them all, executing the same code for each pair of addresses. Something like this:
Sub sumAndClearSomeRanges 'make sum from two ranges and put it to the second range
Dim oDoc As Object, oSheet As Object, data1(), data2(), oRange1 As Object, oRange2 As Object, i&, j&
Dim aAllRangesAddress As Variant
aAllRangesAddress = Array("A43:C52","H43:H52", "A54:C58","H54:H58", "A62:C64","H62:H64") ' and all others
oDoc=ThisComponent
oSheet=oDoc.CurrentController.ActiveSheet
For j = LBound(aAllRangesAddress) To UBound(aAllRangesAddress) Step 2
oRange1=oSheet.getCellRangeByName(aAllRangesAddress(j))
oRange2=oSheet.getCellRangeByName(aAllRangesAddress(j+1))
data1=oRange1.getData
data2=oRange2.getData
for i=lbound(data1) to ubound(data1) 'make sum
data2(i)(0)=Fix(data1(i)(0)+data1(i)(1)+data1(i)(2)+data2(i)(0))
next i
oRange1.clearContents(1023) 'clear all contents in the range
oRange2.setData(data2) 'set new data
Next j
End Sub
Or you can exclude any mention of addresses from the macro code, and instead mark the cells on the sheet with some special style - the macro will process the values of such cells wherever they appear on the sheet and no matter how many there are.
But now, when we know that there will be many such ranges, it makes sense to stop and look back, to think again about the problem that you are trying to solve. Perhaps another approach to the solution will be found, less time-consuming and more efficient. For example, a dialog with three fields for cell values from columns A:C and “OK” and “Cancel” buttons that will automatically appear after double-clicking on a certain row? Perhaps this approach would be clearer to the user of your spreadsheet?