summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sc/source/ui/view/viewfun2.cxx23
1 files changed, 16 insertions, 7 deletions
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index a4406ad3cbaf..2727e0b7f733 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -632,7 +632,10 @@ bool ScViewFunc::AutoSum( const ScRange& rRange, bool bSubTotal, bool bSetCursor
SCCOL nMarkEndCol = nEndCol;
SCROW nMarkEndRow = nEndRow;
ScAutoSum eSum = ScAutoSumNone;
- ScRangeList aSumRangeList;
+ SCROW nColSums = 0;
+ SCCOL nRowSums = 0;
+ SCROW nColSumsStartRow = 0;
+ SCCOL nRowSumsStartCol = 0;
if ( bRow )
{
@@ -656,12 +659,15 @@ bool ScViewFunc::AutoSum( const ScRange& rRange, bool bSubTotal, bool bSetCursor
{
if ( !pDoc->IsBlockEmpty( nTab, nCol, nStartRow, nCol, nSumEndRow ) )
{
+ ScRangeList aRangeList;
// Include the originally selected start row.
const ScRange aRange( nCol, rRange.aStart.Row(), nTab, nCol, nSumEndRow, nTab );
- if ( (eSum = lcl_GetAutoSumForColumnRange( pDoc, aSumRangeList, aRange )) != ScAutoSumNone )
+ if ( (eSum = lcl_GetAutoSumForColumnRange( pDoc, aRangeList, aRange )) != ScAutoSumNone )
{
+ if (++nRowSums == 1)
+ nRowSumsStartCol = aRangeList[0]->aStart.Col();
const OUString aFormula = GetAutoSumFormula(
- aSumRangeList, bSubTotal, ScAddress(nCol, nInsRow, nTab));
+ aRangeList, bSubTotal, ScAddress(nCol, nInsRow, nTab));
EnterData( nCol, nInsRow, nTab, aFormula );
}
}
@@ -690,11 +696,14 @@ bool ScViewFunc::AutoSum( const ScRange& rRange, bool bSubTotal, bool bSetCursor
{
if ( !pDoc->IsBlockEmpty( nTab, nStartCol, nRow, nSumEndCol, nRow ) )
{
+ ScRangeList aRangeList;
// Include the originally selected start column.
const ScRange aRange( rRange.aStart.Col(), nRow, nTab, nSumEndCol, nRow, nTab );
- if ( (eSum = lcl_GetAutoSumForRowRange( pDoc, aSumRangeList, aRange )) != ScAutoSumNone )
+ if ( (eSum = lcl_GetAutoSumForRowRange( pDoc, aRangeList, aRange )) != ScAutoSumNone )
{
- const OUString aFormula = GetAutoSumFormula( aSumRangeList, bSubTotal, ScAddress(nInsCol, nRow, nTab) );
+ if (++nColSums == 1)
+ nColSumsStartRow = aRangeList[0]->aStart.Row();
+ const OUString aFormula = GetAutoSumFormula( aRangeList, bSubTotal, ScAddress(nInsCol, nRow, nTab) );
EnterData( nInsCol, nRow, nTab, aFormula );
}
}
@@ -707,10 +716,10 @@ bool ScViewFunc::AutoSum( const ScRange& rRange, bool bSubTotal, bool bSetCursor
// original selection. All extended by end column/row where the sum is put.
const ScRange aMarkRange(
(eSum == ScAutoSumSum ?
- (aSumRangeList.size() == 1 ? aSumRangeList[0]->aStart.Col() : nStartCol) :
+ (nRowSums == 1 ? nRowSumsStartCol : nStartCol) :
rRange.aStart.Col()),
(eSum == ScAutoSumSum ?
- (aSumRangeList.size() == 1 ? aSumRangeList[0]->aStart.Row() : nStartRow) :
+ (nColSums == 1 ? nColSumsStartRow : nStartRow) :
rRange.aStart.Row()),
nTab, nMarkEndCol, nMarkEndRow, nTab );
MarkRange( aMarkRange, false, bContinue );