0

This question is a more general approach of this one:

The original question says:

I have a 2D array, and I want to see the blank cells in one column.

I would like to generalise this into:

I have a 2D array, and I want to see the cells, satisfying a condition, in one column.

Is there a general approach for this?

As an example, let's take this:

      A    B    C    D
   ==== ==== ==== ====
1 |   1   12    3    4
2 |  11   22   53   34
3 |   1   32   33    4

Imagine I'd like to list values, smaller than 5, in a column.

The result would need to be:

1
3
4
1
4
(without empty cells in between)

Is there a general approach (I mean a formula, not a VBA macro) for this?

Dominique
  • 16,450
  • 15
  • 56
  • 112

1 Answers1

3

You can use FILTERXML() & TEXTJOIN() if your version of excel supports.

=FILTERXML("<t><s>"&TEXTJOIN("</s><s>",TRUE,A1:D3)&"</s></t>","//s[.<5]")
  • <t> & <s> are used to make a xml string. We can use any charecter like <x>, <y> but must be in vaild xml format.
  • Here "<t><s>"&TEXTJOIN("</s><s>",TRUE,A1:D3)&"</s></t>" will construct a valid xml string to process by FILTERXML().
  • //s will return all s node while [.<5] will filter only nodes less than 5.

More about FILTERXML() here from @JvdV Extract substrings from string using FILTERXML()

enter image description here

Harun24hr
  • 30,391
  • 4
  • 21
  • 36
  • What's the meaning of the tags `` and ``? Is there a link between the tag `` and the formulated condition `s[.<5]`? (Sorry, but I don't know the `FILTERXML()` function that well) – Dominique Apr 05 '21 at 09:15