Search code examples
loopsgoogle-sheetslambdavlookupoffset

Google sheets: How to add a helper row to fill gaps in a list of customer ID row


I'm trying to figure out a way how to fill blank cells in a row with previous existing data. I have an array of data with a customer ID-key I'd need to copy to some lines that don't automatically have the key ID due to gaps in source data.

Here's the situation. Gaps in data in Columns A:

Column A Column B
Cell 1 Cell 2
Cell 4
Cell 6
Cell 7 Cell 8
Cell 10
Cell 12

This question comes in two parts. See the wished solution I tried to create below.


Solution

  • use:

    =ARRAYFORMULA(IF(B2:B="",, VLOOKUP(ROW(A2:A), IF(A2:A<>"", {ROW(A2:A), A2:A}), 2, 1)))
    

    enter image description here


    update:

    =ARRAYFORMULA(IF(B2:B="";; VLOOKUP(ROW(A2:A); IF(A2:A<>""; {ROW(A2:A)\ A2:A}); 2; 1)))
    

    or:

    =SCAN(; A2:INDEX(A:A; MAX(ROW(B:B)*(B:B<>""))); LAMBDA(a; b; IF(b=""; a; b)))
    

    see: stackoverflow.com/questions/73767719

    enter image description here