ajit maurya
ajit maurya

Reputation: 15

Need Help getting Multiple Values in Single Cell with Condition to be satisfied in excel

I need help in getting values in a single cell with the condition to be satisfied.

I want defaulter who is having a value of less than 95% in a single cell.

e.g. enter image description here

Upvotes: 1

Views: 87

Answers (1)

Scott Craner
Scott Craner

Reputation: 152465

If one has the dynamic array formula FILTER and TEXTJOIN:

=TEXTJOIN(CHAR(10),TRUE,FILTER(A2:A7,E2:E7<.95))

Make sure that the output cell has Wrap Text enabled.

enter image description here


If one has TEXTJOIN but not FILTER (Excel 2019) then use this array formula:

=TEXTJOIN(CHAR(10),TRUE,IF(E2:E7<.95,A2:A7,""))

This would need to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.


If neither then place this code in a standard module:

Function TEXTJOINIFS(rng As Range, delim As String, ParamArray arr() As Variant)
    Dim rngarr As Variant
    rngarr = Intersect(rng, rng.Parent.UsedRange).Value

    Dim condArr() As Boolean
    ReDim condArr(1 To Intersect(rng, rng.Parent.UsedRange).Rows.Count) As Boolean


    Dim i As Long
    For i = LBound(arr) To UBound(arr) Step 2
        Dim colArr() As Variant
        colArr = Intersect(arr(i), arr(i).Parent.UsedRange).Value
        Dim j As Long
        For j = LBound(colArr, 1) To UBound(colArr, 1)

            If Not condArr(j) Then
                Dim charind As Long
                charind = Application.Max(InStr(arr(i + 1), ">"), InStr(arr(i + 1), "<"), InStr(arr(i + 1), "="))
                Dim opprnd As String
                If charind = 0 Then
                    opprnd = "="
                Else
                    opprnd = Left(arr(i + 1), charind)
                End If
                Dim t As String
                t = """" & colArr(j, 1) & """" & opprnd & """" & Mid(arr(i + 1), charind + 1) & """"
                If Not Application.Evaluate(t) Then condArr(j) = True
            End If
        Next j
    Next i

    For i = LBound(rngarr, 1) To UBound(rngarr, 1)
        If Not condArr(i) Then
            TEXTJOINIFS = TEXTJOINIFS & rngarr(i, 1) & delim
        End If
    Next i

    TEXTJOINIFS = Left(TEXTJOINIFS, Len(TEXTJOINIFS) - Len(delim))

End Function

And call it like this:

=TEXTJOINIFS(A2:A7,CHAR(10),E2:E7,"<"&0.95)

enter image description here

Upvotes: 2

Related Questions