Does anyone know how can I Transpose/copy a row from one sheet to another sheet in Googlesheets?
Here is what I want to do: so I have a google spreadsheet file. It has 2 tabs/sheets.
- Now, sheet 1 has a column named: "total."
- Now, what I got to do is to see if this column: "total" in sheet 1 is empty or not.
- If its empty, then I should copy the entire row which has the empty column in sheet 1, to sheet 2.
I know I must use appendRow() function. But that requires hard-coded values. something like this: sheets.appendRow({"a", "b"}) but the row I am trying to append is entered by the users.
What I need to do is to see which row has a empty cell at column I or column 8.
Then take that entire row and copied it over. So far, I was able to get the row which has the empty column at column I. But I can't figure out how to append it/copy it.
I would appreciate your input on this. Because I haven't been able to find any resources that relates to what I need exactly.
Here's the code I have so far.
function insertRecord() {
var sss = SpreadsheetApp.getActiveSpreadsheet().getSheets()[1];
var values = sss.getDataRange().getValues();
var getRangeRow2 = sss.getDataRange().getRow()[5];
var getRangeCol2 = sss.getDataRange().getColumn()[1];
var placeHolder = sss.insertRowsBefore(5, 1);
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
var values = ss.getDataRange().getValues();
var n = 4;
var c = 8;
var getRangeRow = ss.getDataRange().getRow()[n];
var getRangeCol = ss.getDataRange().getColumn()[c];
for(n=4;n<values.length;n++){ // Loops through all values in column 8
var column = values[n][c]; // n represents my rows in the getSheets()[0] // number 8 is the column 8.
var row = values[n];
var col = values[c];
if(column == null)
{ // Currently this will get me the rows where the column I has no value in it. This is what its supposed to do. << I am happy with this.
if(placeHolder)
{
placeHolder = ss.getDataRange(getRangeRow, getRangeCol).copyTo(getRangeRow2, getRangeCol2);
// NOTE: SORRY NOT YELLING. BUT THIS PART IS THE PROBLEM I AM HAVING. IT
// WON'T WORK. IT WONT COPY THE ROW TO THE OTHER SHEET.
}
Logger.log(row, col);
}
}
}
getRow()
return? – TheMastergetRow()
returnsInteger
and not aarray
. Therefore it can't be indexed with[5]
. Get it? Any way the below answer should work. – TheMaster