返回列表 上一主題 發帖

[發問] 如何計算每個欄的累計最大失分

回復 15# cdkee
看不懂你的邏輯
第一組2016/5/5開始 1000,900,700,800,600,300
700到800有得分啊,結果你用1000-300=700失分
而不是分為 1000-700 , 800-300 這兩組失分
表達不清、題意不明確、沒附檔案格式、沒有討論問題的態度~~~~~~以上愛莫能助。

TOP

回復 20# cdkee
插入一般模組,貼上下面code
  1. Function FindMaxLoss(rngInput As Range, Optional order As Integer = 1)
  2.     On Error GoTo ErrHandle
  3.    
  4.     Dim ar, arLoss
  5.     ar = Application.Transpose(rngInput)
  6.     ReDim arLoss(1 To UBound(ar))
  7.    
  8.     Dim i, count As Integer, sum As Double
  9.     Dim indMin As Long, indMax As Long
  10.     indMin = 1: indMax = 1
  11.     i = 2
  12.     Do While i <= UBound(ar)
  13.         If ar(i) < ar(indMin) Then indMin = i
  14.         If ar(i) > ar(indMax) Or i = UBound(ar) Then
  15.             If indMin <> indMax Then
  16.                 count = count + 1
  17.                 arLoss(count) = ar(indMin) - ar(indMax)
  18.                 i = indMin
  19.             End If
  20.             indMin = i
  21.             indMax = i
  22.         End If
  23.         i = i + 1
  24.         DoEvents
  25.     Loop
  26.         
  27.     ReDim Preserve arLoss(1 To count)
  28.     FindMaxLoss = Application.WorksheetFunction.Small(arLoss, order)
  29.     Exit Function
  30.    
  31. ErrHandle:
  32.     FindMaxLoss = CVErr(xlErrValue)
  33. End Function
複製代碼
D7填上公式  =FindMaxLoss(D$20:D$34,1)
D8填上公式  =FindMaxLoss(D$20:D$34,2)
D9填上公式  =FindMaxLoss(D$20:D$34,3)
向右拖曳填滿公式
表達不清、題意不明確、沒附檔案格式、沒有討論問題的態度~~~~~~以上愛莫能助。

TOP

        靜思自在 : 一個缺口的杯子,如果換一個角度看它,它仍然是圓的。
返回列表 上一主題