1

I would like to do something similar to what was solved in the question:

An arrayformula to find the previous non-empty cell in another column

The problem was:

If I have a column "input", I would like the column "ouput" to be filled with the preceding value of the "input" column.

input - ouput a a a a b b b b b c c c c c

It was a great answer, however, the ArrayFormula works with an user-specified range:

=ArrayFormula(vlookup(ROW(1:10),{IF(LEN(A1:A10)>0,ROW(1:10),""),A1:A10},2))

How would I make the function to automatically get the last row that it has to take?

Specifically, I would like to know how to get automatically the number 10 of the last function.

I have tried to use INDIRECT but it finds an error.

=ArrayFormula(vlookup(ROW(INDIRECT("B3:B"&INDEX(SORT(B:B,ROW(B:B),FALSE),1))),{IF(LEN(INDIRECT("B3:B"&INDEX(SORT(B:B,ROW(B:B),FALSE),1))>0,ROW(INDIRECT("3:"&INDEX(SORT(B:B,ROW(B:B),FALSE),1)),""),INDIRECT("B3:B"&INDEX(SORT(B:B,ROW(B:B),FALSE),1)},2)))))

This part: INDIRECT("B3:B"&INDEX(SORT(B:B,ROW(B:B),FALSE),1)) is used to get the last value of a column.

I have created a spreadsheet with the functions: https://docs.google.com/spreadsheets/d/15jbXZbixRYxJSRQuKgBU8BWN6KYNjwwT5PzvYp986Ww/edit#gid=0

Any help would be appreciated.

4
  • 1
    What was your INDIRECT attempt? What was the error, exactly?
    – ale
    Mar 1, 2016 at 17:31
  • I've just updated the question to present it @AlE.
    – EumirAMC
    Mar 1, 2016 at 18:06
  • Why not just refer the entire column? E.g., =ArrayFormula(vlookup(ROW(B3:B),{IF(LEN(B3:B)>0,ROW(B3:B),),B3:B},2))
    – user79865
    Mar 1, 2016 at 21:54
  • @Sally using open ended references will fill the entire column. Considering the functions used it's not a big deal. Anyway, I added an answer including ARRAY_CONSTRAIN to limit the number of rows returned.
    – Rubén
    Mar 2, 2016 at 23:28

2 Answers 2

1

Can't edit your spreadsheet, but this formula (entered in C3)

=ArrayFormula(if(row(B3:B) <= max(if(not(isblank(B3:B)), row(B3:B))),vlookup(row(B3:B),filter({row(B3:B),B3:B},len(B3:B)),2),))

should bring you the output you expected.

1
  • Thank you, that was it, your solution is the best because it doesn't need to specify the last value of the column and it also leaves the unmodified cells as blanks.
    – EumirAMC
    Jan 16, 2017 at 15:12
1

The following formula automatically fills the output column and stops at the row 10. To fill more rows, replace 10 by the desired number of rows or by a function / subformula that calculates the required rows.

=ArrayFormula(
   ARRAY_CONSTRAIN(
     VLOOKUP(ROW(A:A),{IF(LEN(A:A)>0,ROW(A:A),""),A:A},2),
     10,
     1
   )
 )
1
  • I tried entering the part INDIRECT("B3:B"&INDEX(SORT(B:B,ROW(B:B),FALSE),1)) instead of the 10 but it didn't work.
    – EumirAMC
    Jan 16, 2017 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.