Home » excel » google sheets – How to print in excel with iteration per column based on value (number)

google sheets – How to print in excel with iteration per column based on value (number)

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am trying to achieve something that increments per column based on the value given.
Like,

if A1 = "ABC" and B1 = 3 then C1 = "ABC", D1 = "ABC" and E1 = "ABC".
If A1 = "ABC" and B1 = 1 then C1 = "ABC"
If A1 = "ABC" and B1 = 2 then C1 = "ABC" and D1 = "ABC"

I haven’t tried anything yet, I only have the logic.

I have seen some codes but it’s VB, what i was trying to achieve was using formula.

Expected output is what above describes.

Thanks

How to&Answers:

Excel

In cell C1:

=IF(COLUMN(A1)<=$B1,$A1,"")

Drag right till the max you think you must go based on B1

enter image description here

Google Spreadsheets

In cell C1:

=ARRAYFORMULA(IF((COLUMN(C1:KN1)-2)<=B1,A1,""))

Change KN1 to whichever column would be the max and enter.

enter image description here

Answer:

You could do it in one go with Google sheets:

=ArrayFormula(if(column(C1:indirect(address(counta(A:A),max(B:B)+2)))>B:B+2,"",A:A))

enter image description here

There’s also

=ArrayFormula(if(A:A="","",split(rept(A:A&"|",B:B),"|")))

but this is limited to 50K characters per row.