总计相应列值的最小值

我有两列数字。 我想在一个单独的单元格中计算一笔款项。 总和将包括这两列中相应单元格的最小值。

例:

A | B -------- [1] 1 | 2 [2] 4 | 3 [3] 0 | 1 [4] 5 | 5 

我需要一个计算公式1 + 3 + 0 + 5的单元格

 * 1 is the MIN(A1,B1), * 3 is the MIN(A2,B2) * 0 is the MIN(A3,B3) * 5 is the MIN(A4,B4) 

这是可能的一个单一的公式(独立于#rows)?

目前与LibreOffice Calc一起工作,但Excel解决scheme更受欢迎。

你可以使用一个数组公式 (doc for Libre Office和Excel ):

 =SUM(IF(A1:A4<B1:B4, A1:A4, B1:B4)) 

Ctrl + Shift + Enter确认,而不是简单的确认。

那么,你可以用一个公式做到这一点,但它不是很可扩展。 例如,你可以这样做:

 =SUM(MIN(A1:B1),MIN(A2:B2),MIN(A3:B3), MIN(A4:B4)) 

这将在你描述的情况下工作。 但是,我明白,如果你有大量的行,那么这将不能很好地缩放。 在这种情况下,我认为你需要一个VBAmacros,因为我看不到这样做的方法。 我准备通过一些Excel公式大师来纠正。

对于VBA解决scheme,您可以尝试以下(在OzGrid论坛中find):

 Function sumOfMax(ByVal inputRange As Range, Optional doMin As Boolean) As Double Dim inRRay As Variant Dim currentMax As Double Dim i As Long, j As Long Set inputRange = Application.Intersect(inputRange, inputRange.Parent.UsedRange) If Nothing Is inputRange Then Exit Function inRRay = inputRange.Value For i = 1 To UBound(inRRay, 1) currentMax = Val(inRRay(i, 1)) For j = 1 To UBound(inRRay, 2) If (Val(inRRay(i, j)) > currentMax) Xor doMin Then currentMax = Val(inRRay(i, j)) Next j sumOfMax = sumOfMax + currentMax Next i End Function 

设置为TRUE ,可选参数计算最小值,而不是此macros默认计算的最大值。 在你的例子中,你需要像这样调用它:

 =sumOfMax(A1:B4, TRUE) 

只要记住你需要把代码放在一个标准的代码模块中。