Excel:如何在非零值之后选择行中的第一个零

时间:2017-11-30 21:45:01

标签: excel excel-formula

在一行数据中,如何在非零值之后找到第一个零所在的列? Check this image for the example.

5 个答案:

答案 0 :(得分:1)

使用此公式:

=INDEX($1:$1,AGGREGATE(15,6,COLUMN(B2:E2)/((A2:D2<>0)*(B2:E2=0)),1))

enter image description here

答案 1 :(得分:0)

=FIND("0",TEXTJOIN(,,A2:E2),FIND("1",TEXTJOIN(,,A2:E2)))

编辑:

使用任何非零值:

=INDEX(OFFSET(A2,-(ROW()-1),MATCH(TRUE,INDEX(A2:E2<>0,),0),,COLUMNS(A2:E2)-MATCH(TRUE,INDEX(A2:E2<>0,),0)),1,MATCH(0,OFFSET(A2,0,MATCH(TRUE,INDEX(A2:E2<>0,),0),,COLUMNS(A2:E2)-MATCH(TRUE,INDEX(A2:E2<>0,),0)),0))

答案 2 :(得分:0)

Sub FindNonZero()

For i = 2 To 4
    For j = 1 To 5
        If Cells(i, j).Value <> 0 Then
            For k = j To 5
                If Cells(i, k).Value = 0 Then
                    Cells(i, 7).Value = "COL" & k
                    Exit For
                End If
            Next k
        Exit For
        End If
    Next j
Next i

End Sub

Before

After

答案 3 :(得分:0)

您可以在VBA中创建自己的功能

Function FindZero(TargetRange as range) As Long
   Dim aCell as range 

   For each aCell in TargetRange 
      if aCell>0 AND aCell.Offset(0,1) = 0 then
         FindZero = aCell.Offset(0,1).Column
         Exit For
      end if 
   next aCell
end function 

然后在某个单元格中你只需要

=FindZero(A1:G1)

`

答案 4 :(得分:0)

这个INDEX / AGGREGATE / MATCH应该为你做。

=INDEX(INDEX(C$1:G$1, 1, AGGREGATE(15, 6, COLUMN(A:E)/(C2:G2>0), 1)):G$1, MATCH(0, INDEX(C2:G2, 1, AGGREGATE(15, 6, COLUMN(A:E)/(C2:G2>0), 1)):G2, 0))

请注意,COLUMN(A:E)返回 C $ 1中的位置:G $ 1和C2:G2。

enter image description here