Excel公式=求和2列,find总和的最大值,并使用最大行从另一列获取数据?
想象一下,我有3列
Date Data1 Data2 1st 4 5 2nd 7 8
我想要做的是总结Data1和Data2在一起,并find最大的发生date。
目前我使用=Max (INDEX (B2:B3 + C2:C3))
来获得总和的最大值,但我不能想到如何获得最大发生的行,以获得date
想到使用索引匹配来做到这一点,但是却一无所获
我不觉得你是否也使用VBA,我以后会把这个公式编码到VBA中。 使用Excel 2007
请看下面的图片和公式来达到你的效果(如果我理解正确的话)
单元格E2的公式:
=INDEX(A:A,MATCH(MAX(D1:D4),D1:D4,0),1)
对于VBA解决scheme:
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