Quantcast
Channel: Active questions tagged worksheet-function - Super User
Viewing all articles
Browse latest Browse all 929

How can I apply an array formula to each value returned by another array formula?

$
0
0

I'm using Microsoft 365 and want to find a way in Excel to sequentially apply array formulas - one on the output of the other - to yield a 2D table.

Specifically, I want to apply a regex with capture groups to a user-provided block of text. In an ideal world REGEXEXTRACT() would return a 2D array where each row corresponds to a match, and each column corresponds to a capture group. However, REGEXEXTRACT() currently only returns (using the return_mode argument) either a 1D array containing the capture groups of the first match, or a 1D array containing each match in full (taking no account of capture groups).

So the workaround I planned was to use the second option to output all the matches from REGEXEXTRACT(), then TRANSPOSE() them so they run vertically. A second REGEXEXTRACT() in the next column, applying the same regex, would then operate on each of the matches and output the capture groups horizontally.

Unfortunately, although 1) the first REGEXEXTRACT() works fine 2) the second REGEXEXTRACT() works fine when manually applied to each row output from the first, I haven't been able to find a way to successfully automatically replicate the formula for however many rows there are. If I use the spilled range operator #, although the formula then spills vertically, it doesn't output anything horizontally, meaning only the first capture group is returned.

Here's a simplified example showing the two REGEXEXTRACT() formulas working for the first row:

  • B1: the Regex (in this case, returning two capture groups of numerical data)
  • B2: the string to be searched
  • B5: =TRANSPOSE(REGEXEXTRACT(B2,B1,1,1))
  • C5: =REGEXEXTRACT(B5,$B$1,2,1)

Spreadsheet showing sequential REGEXEXTRACT() formulas working

Here's an example showing the spill not operating both horizontally and vertically:

  • B1, B2, B5: as above
  • C5: =REGEXEXTRACT(B5#,$B$1,2,1)

Spreadsheet showing spill not operating both horizontally and vertically

I'm sure this could be done in VBA but I'd prefer not to go down that route. I feel there's something simple I'm missing - is there?


Viewing all articles
Browse latest Browse all 929

Trending Articles