Excel公式=总和2列,找到总和的最大值并使用最大行从另一列获取数据?

时间:2015-06-30 07:35:18

标签: excel excel-vba excel-formula excel-2007 vba

想象一下,我有3列

Date   Data1  Data2
1st      4      5
2nd      7      8

我想要做的是将Data1和Data2加在一起,找到最大值发生的日期。

目前我使用=Max (INDEX (B2:B3 + C2:C3))来获取总和的最大值,但我不能想到如何获得最大值出现的行以获取日期

考虑使用索引匹配来做但却处于亏损状态

我没有发现你是否使用VBA太牛了我以后将公式编码到VBA中。使用excel 2007

1 个答案:

答案 0 :(得分:1)

请参阅下面的图片和公式以获得结果(如果我理解正确的话)

enter image description here

细胞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
相关问题