Link to example sheet with faux data:
So, here’s a formula that works, but iterating the pattern is way too long to type by hand. I tried using chatGPT to simply iterate the pattern but it basically breaks. It either doesn’t work, messes up the pattern or, the last time, it reset the conversation and remembers none of it. Yikes.
”’=FILTER(VSTACK(E6:F,G6:H,I6:J,K6:L), (VSTACK(E6:E,G6:G,I6:I,K6:K) <> “”) + (VSTACK(F6:F,H6:H,J6:J,L6:L) <> “”) )”’
To cover all 365 days, I need this to iterate out to Column ABH.
I’ve tried an apps script (though Id rather it was a formula). It works until column 370 then it jumps back to column A for some reason and I cannot understand this weird issue. The code is as follows:
function stackColumns() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lastColumn = 736; // Adjust to your actual last column
var lastRow = 100; // Adjust to your actual last row
// Define constants for batch processing
var startColumn = 5; // Starting column index (E = column 5)
var batchSize = 100; // Number of columns to process in each batch
var stackedData = [];
// Loop through batches of columns
for (var start = startColumn; start <= lastColumn; start += batchSize) {
var end = start + batchSize - 1;
if (end > lastColumn) {
end = lastColumn;
}
// Get data range for the current batch of columns
var dataRange = sheet.getRange(6, start, lastRow - 5 + 1, end - start + 1);
var values = dataRange.getValues();
var numRows = values.length;
var numCols = values[0].length;
// Process each column pair in the current batch
for (var i = 0; i < numCols - 1; i += 2) { // Increment by 2 for column pairs
var currentStartColumn = start + i;
var currentEndColumn = start + i + 1;
// Process each row in the current column pair
for (var row = 0; row < numRows; row++) {
var startValue = (currentStartColumn <= numCols) ? values[row][currentStartColumn - start] : "";
var endValue = (currentEndColumn <= numCols) ? values[row][currentEndColumn - start] : "";
// Skip processing if both values are empty
if (startValue === "" && endValue === "") {
continue;
}
// Push the data pair to stackedData
var rowData = [
startValue,
endValue
];
stackedData.push(rowData);
}
}
}
// Clear existing content and paste the stacked data starting from a specific cell
var outputRange = sheet.getRange(7, 739, stackedData.length, 2); // Adjust the number of columns (2 for each pair)
outputRange.clearContent();
outputRange.setValues(stackedData);
}
I’m at a total loss here. This shouldn’t be that difficult but it’s defeated me.
2