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:


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.


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.

  • 1
    What was your INDIRECT attempt? What was the error, exactly? – ale Mar 1 '16 at 17:31
  • I've just updated the question to present it @AlE. – EumirAMC Mar 1 '16 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 '16 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 '16 at 23:28
up vote 1 down vote accepted

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.

  • 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 '17 at 15:12

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.

  • 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 '17 at 15:13

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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