I have two Google Sheets with identical layouts that are filled in by independent teams:
Sheet 1:
team1_entry1 243
team1_entry2 546
etc
...
XXX
Sheet 2:
team2_entry1 166
team2_entry2 888
...
XXX
I need to see the data from both sheets in one table, which I can then filter and sort using Filter Views. I wrote a simple Apps Script function to go through each sheet and grab all the values until it hits "XXX". The collected data is then written as a two-dimensional array in my sheet. (I use IMPORTRANGE()
of this data into another sheet, from which I generate my Filter Views, etc.)
This workflow doesn't work offline (Apps Script needs the internet to run), and I would like to be able to work on this data when I don't have internet access.
Would it be possible to do this kind of sheet data concatenation using some kind of array formula wizardry?
My currently-working script code, for reference:
function CreateMasterTableTest( ) {
var name_of_a_sheet = 'Team1Sheet';
var name_of_b_sheet = 'Team2Sheet';
var num_tables = 2;
var database_terminating_string = 'XXX';
var start_of_data_row_index = 1; // 2nd row in the sheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var all_values = [];
var a_sheet = ss.getSheetByName( name_of_a_sheet );
var range = a_sheet.getDataRange();
all_values[ 0 ] = range.getValues();
var b_sheet = ss.getSheetByName( name_of_b_sheet );
var range = b_sheet.getDataRange();
all_values[ 1 ] = range.getValues();
var output_array = [];
var global_row_index = 0;
var end_of_data_encountered = false;
////////////////////////////////////////////////////////////////////
// Now I have to reserve space for the second dimension
////////////////////////////////////////////////////////////////////
for ( var i = 0; i < ( all_values[ 0 ].length + all_values[ 1 ].length ); i++ ) {
output_array[ i ] = output_array[ i ] || [];
}
////////////////////////////////////////////////////////////////////
// Walk through each row and each column of each sheet
////////////////////////////////////////////////////////////////////
var a_num_rows = all_values[ 0 ].length;
var a_num_cols = all_values[ 0 ][ 0 ].length; // this gets the number of cols
for ( var table_index= 0; table_index < num_tables; table_index++ ) {
for ( var row = 0; row < a_num_rows; row++ ) {
for ( var col = 0; col < a_num_cols; col++ ) {
temp_val = String( all_values[ table_index ][ row ][ col ] ); //#VALUE!
///////////////////////////////////////////////////////////////////////////
// At this point we shall check for the terminating string
///////////////////////////////////////////////////////////////////////////
if ( database_terminating_string == temp_val ) {
end_of_data_encountered = true;
break;
}
if ( start_of_data_row_index <= row ) {
output_array[ row - start_of_data_row_index + global_row_index ][ col ] = temp_val;
}
}
if ( end_of_data_encountered == true ) {
end_of_data_encountered = false;
global_row_index = row - 1;
break;
} //end of if
} // end of row for loop
} // end of tables for loop
return output_array;
}
Edit 2: Here is the sheet formula I have come up with, but I can't get it to work for both sheets:
=Indirect( "Sheet1!A3:HA" & Match( "XXX", Sheet1!A3:A1000, 0 ) + 1 )
And likewise for Sheet2
=Indirect( "Sheet2!A3:HA" & Match( "XXX", Sheet2!A3:A1000, 0 ) + 1 )
Below doesn't work for me:
=concat( Indirect( "Sheet1!A3:HA" & Match( "XXX", Sheet1!A3:A1000, 0 ) + 1 ), Indirect( "Sheet2!A3:HA" & Match( "XXX", Sheet2!A3:A1000, 0 ) + 1 ) )
I need something similar to concat that works for Arrays, perhaps.
Edit3: Seem to have found a solution
Instead of concat above, use {array1;array2} approach.
In other words, in my case it is:
={Indirect( "Sheet1!A3:HA" & Match( "XXX", Sheet1!A3:A1000, 0 ) + 1 ); Indirect( "Sheet2!A3:HA" & Match( "XXX", Sheet2!A3:A1000, 0 ) + 1 ) }
={Indirect( "Sheet1!A3:HA" & Match( "XXX", Sheet1!A3:A1000, 0 ) + 1 ); Indirect( "Sheet2!A3:HA" & Match( "XXX", Sheet2!A3:A1000, 0 ) + 1 ) }
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.