简体   繁体   中英

Using ArrayFormula with Indirect to combine sheets

I am trying to combine data from other sheets into a single sheet. I thought I could use a formula to find the last row in each sheet and combine with an Indirect ArrayFormula but that doesn't work.

Indirect("ARRAYFORMULA({'Sheet1'!A2:J"&ArrayFormula(MAX(IF(NOT(ISBLANK ('Sheet1'!A1:A10000)), ROW('Sheet1'!A1:A10000),0)))&";'Sheet2'!A2:J"&ArrayFormula(MAX(IF(NOT(ISBLANK ('Sheet2'!A1:A10000)), ROW('Sheet2'!A1:A10000),0)))})")

The Indirect and ArrayFormula combo doesn't seem to be the answer as it errors out - it appears you can't run an indirect and array formula together.

EDIT: Using the formula above without the Indirect and finding the last blank row will combine the sheets when I keep a long row range but it keeps all the blank rows and spreads the data of each sheet out too much.

ARRAYFORMULA({'Sheet1'!A2:J100";'Sheet2'!A2:J100)})

Which is why I was trying to use the max arrayformula to find the last row in each sheet to consolidate the blank rows.

ArrayFormula(MAX(IF(NOT(ISBLANK ('Sheet1'!A1:A10000)), ROW('Sheet1'!A1:A10000),0)))

由于我误解了您的问题,这是您提供的公式的替代方法。

=QUERY({Sheet2!A:J; Sheet3!A:J}, "select * where Col1 <>'' ")

In a google spreadsehet, if you want to retrieve the last row of both sheets you can try:

={INDEX(Sheet1!A:J, MAX(FILTER(ROW(Sheet1!A:J),NOT(ISBLANK(Sheet1!A:A))))); INDEX(Sheet2!A:J, MAX(FILTER(ROW(Sheet2!A:J),NOT(ISBLANK(Sheet2!A:A)))))}

this will put the last row of the second sheet in a row under the last row of the first sheet. In case you want those rows to appear in the same row, try:

={INDEX(Sheet1!A:J, MAX(FILTER(ROW(Sheet1!A:J),NOT(ISBLANK(Sheet1!A:A))))), INDEX(Sheet2!A:J, MAX(FILTER(ROW(Sheet2!A:J),NOT(ISBLANK(Sheet2!A:A)))))}

I figured out you can't use indirect outside of an arrayformula but you can use it inside { }

 ={INDIRECT("'Sheet1'!A2:J"&MAX(FILTER(ROW(Sheet1!A:J),NOT(ISBLANK(Sheet1!A:A))))) ; INDIRECT("'Sheet2'!A2:J"&MAX(FILTER(ROW(Sheet2!A:J),NOT(ISBLANK(Sheet2!A:A)))))}

This combines the sheets perfectly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM