[英]Excel - How to create a formula to return a cell to the right of the result of another formula
基本上,我在一個單元格中有以下公式,以返回行中的第一個非0值:
=INDEX('Financials Cashflow Year'!C30:M30,MATCH(TRUE,INDEX('Financials Cashflow Year'!C30:M30<>0,),0))
我想要一個公式來返回第一個公式選擇的那個單元格右邊的單元格的值。
假設我們有第一張工作表:
0 0 0 4 3 2
表格2我希望看到這些公式。 可擴展的東西。
4 3 2
我認為您需要一個數組公式。 代替匹配,使用SMALL函數獲取所需的物品,如下所示:
={INDEX('Financials Cashflow Year'!$C30:$M30,1,SMALL(IF('Financials Cashflow Year'!$C30:$M30>0,COLUMN('Financials Cashflow Year'!$C30:$M30)),2)-2)}
IF函數獲取一個列號數組,其中行的值大於零。
然后,Small函數的2參數將帶回第二個最左列的單元格值(該值不為零)。
即在上面的示例中,它將帶回3,類似地,如果將參數更改為1,它將帶回4。
If語句獲取索引中大於零的值的列號。
注意 :打組合鍵Ctrl + Shfit + Enter提交而不是直接輸入Note2 :我注意到您正在跨行工作,因此我認為您需要在“小”之前加上“,1”
=INDEX(C30:M30,MATCH(TRUE,INDEX(C30:M30<>0,),0)+1)
會在第一個公式的右邊為您提供第一個單元格的值,但是由於您似乎在尋找更具動態性的內容,因此對於第一個公式右邊的第二個單元格來說,這樣做的效果難以置信公式,您需要這樣做:
=INDEX(C30:M30,MATCH(TRUE,INDEX(C30:M30<>0,),0)+2)
抓住所示公式右邊的所有單元格的最佳選擇是轉置和過濾或使用VBA,例如VBA:
Sub toRightOfZeros()
Dim rng, cell As Range
Dim startCellCol, destCellLocX As Integer
Dim ValsArr() As String
Dim wb As Workbook
Dim foundNotZero As Boolean
Set wb = ThisWorkbook
destCellLocX = 1
foundNotZero = False
With wb.Sheets("Sheet1")
Set rng = .Range(.Cells(30, 3), .Cells(30, 13))
End With
For Each cell In rng
If foundNotZero = False Then
If Not cell.Value = 0 Then
foundNotZero = True
startCellCol = cell.Column
Exit For
End If
End If
Next
With wb.Sheets("Sheet1")
Set rng = .Range(.Cells(30, startCellCol), .Cells(30, 13))
End With
For Each cell In rng
With wb.Sheets("Sheet2")
.Cells(1, destCellLocX).Value = cell.Value
End With
destCellLocX = destCellLocX + 1
Next
End Sub
輸入(在C30:M30中): 0 0 0 0 365 788 940 239 12 0 99
輸出(第2頁): 365 788 940 239 12 0 99
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.