Below are two macros that have similar code, in fact so similar I believe whatever macro is second is causing the 1st macro not to work. For the second macro I changed Orange1 and Orange2 to Orange3 and Orange4 along with data1 and data2 to data3 and data4, and though the macro still worked it would still not let the first one work. I then thought to change the i&
to k&
, but that caused the macro to not work at all.
Please understand that each macro works fine when placed in their own separate buttons but not together in the same button.
Here is the first macro in the button:
Sub sumAndClearAllRanges3 '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("A63:C72","I63:I72", "A74:C78","I74:I78", "A80:C90","I80:I90", "A92:C98","I92:I98", "A100:C118","I100:I118", "A120:C126","I120:I126", "N63:P74","V63:V74", "N76:P83","V76:V83", "N85:P88","V85:V88", "N90:P99","V90:V99", "N101:P109","V101:V109", "N112:P126","V112:V126" ) ' 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(1) 'clear all contents in the range
oRange2.setData(data2) 'set new data
Next j
end Sub
Here is the second macro that I want to place below the first one in the same button:
Sub AddStatIncrease '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&
oDoc=ThisComponent
oSheet=oDoc.CurrentController.ActiveSheet
oRange1=oSheet.getCellRangeByName("I21:I28")
oRange2=oSheet.getCellRangeByName("B21:B28")
data1=oRange1.getData
data2=oRange2.getData
for i=lbound(data1) to ubound(data1) 'make sum
data2(i)(0)=data1(i)(0)+data2(i)(0)
next i
oRange1.clearContents(1) 'clear all contents in the range; number in SDK com.sun.star.sheet.CellFlags
oRange2.setData(data2) 'set new data
End Sub