簡體   English   中英

Excel公式=總和2列,求和的最大值,並使用最大行從另一列獲取數據?

[英]Excel formula = Sum 2 columns, find the max of the sum and get data from another column using the max row?

想象一下我有3列

Date   Data1  Data2
1st      4      5
2nd      7      8

我想做的是將Data1和Data2求和,然后找到最大值發生的日期。

目前我使用=Max (INDEX (B2:B3 + C2:C3))來獲取總和的最大值,但是我無法考慮如何獲取發生最大值的行以獲取日期

想到使用索引匹配來做到這一點,但atm迷茫了

我找不到您是否也使用VBA,以后不會將該公式編碼到VBA中。 使用Excel 2007

請查看下面的圖片和公式以實現您的結果(如果我正確理解的話)

在此處輸入圖片說明

單元格E2的公式:

=INDEX(A:A,MATCH(MAX(D1:D4),D1:D4,0),1)

對於VBA解決方案:

Sub LargeFind()
Dim wb As Workbook
Dim ws As Worksheet
Dim lastRow, currentLarge, largeRow As Long

Set wb = ActiveWorkbook 'Your workbook
Set ws = wb.Sheets("Sheet1") 'Your sheet name

lastRow = ws.Range("A" & Rows.Count).End(xlUp).Row

currentLarge = 0
largeRow = 0
For i = 2 To lastRow
    ' B & C are the columns where your data is
    If ws.Range("B" & i).Value + ws.Range("C" & i).Value > currentLarge Then
        currentLarge = ws.Range("B" & i).Value + ws.Range("C" & i).Value
        largeRow = i
    End If
Next

ws.Range("D2").Value = ws.Range("A" & largeRow).Value '<-- "D2" is your output cell


End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM