1

Is there someone who can help me to break down this long formula and ,by examining the independent elements, help us to understand how it works?

It takes two contiguous columns, in this case A and B. First a value from A is taken. If there is a next value down A, it will repeat the actual value until that row. If there's no values left in A, it return "" (blank)

So, in "B1" we write this very long formula:

ArrayFormula(IF(ROW(A:A)<=MATCH(2;1/(A:A<>"");1);LOOKUP(ROW(A:A);ROW(A:A)/IF(A:A<>"";TRUE;FALSE);A:A);))

The result is like this:

A B
foo foo (here goes the formula)
foo
bar bar
bar
bar
qux qux
" "
" "
" "
" " (blank cells continue till the end of column)

This array is quite useful, but I guess if there is a cleaner formula, or a better approach to this task... I suspect thats this formula is a turnaround and Spreadsheets must have an elegant resource to get done this kind of task.

4

2 回答 2

0

利用:

=ARRAYFORMULA(IF(B:B="",, VLOOKUP(ROW(A:A), IF(A:A<>"", {ROW(A:A), A:A}), 2, 1)))
于 2021-09-11T05:57:05.907 回答
0

尝试这个:

=ARRAYFORMULA(
  IF(
    ROW(A:A) > MATCH(2, 1 / (A:A <> "")),,
      VLOOKUP(ROW(A:A), FILTER({ROW(A:A), A:A}, A:A <> ""), 2)
  )
)

在此处输入图像描述

MATCH(2, 1 / (A:A <> ""))为您提供列中最后一个非空单元格的行号A:A


或者如果顶部可能有空白单元格,则使用附加条件:

=ARRAYFORMULA(
  IF(
      (ROW(A:A) > MATCH(2, 1 / (A:A <> "")))
    + (ROW(A:A) < MATCH("*", A:A,)),,
      VLOOKUP(ROW(A:A), FILTER({ROW(A:A), A:A}, A:A <> ""), 2)
  )
)

在此处输入图像描述

于 2021-09-18T06:51:53.917 回答