Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iloveitaly/f49681f842ed11a27e0ccf624789f7a2 to your computer and use it in GitHub Desktop.
Save iloveitaly/f49681f842ed11a27e0ccf624789f7a2 to your computer and use it in GitHub Desktop.
// https://webapps.stackexchange.com/questions/52241/custom-data-transpose
function transposeColumns() {
// loading sheets to work with
var ss = SpreadsheetApp.getActiveSpreadsheet();
var invoices = ss.getSheetByName("Invoices");
var bills = ss.getSheetByName("Bills");
var sheet = ss.getSheetByName("Vesta");
// we need to know how wide and tall is the sheet
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var activeR = 2;
var netToOwnerIndex = 32
var comissionIndex = 34;
var serviceFeeIndex = 35;
var taxIndex = 36;
for(var r = activeR; r <= lastRow;r++){
var netToOwner = sheet.getRange(r,netToOwnerIndex).getValue();
var comission = sheet.getRange(r,comissionIndex).getValue();
var serviceFee = sheet.getRange(r,serviceFeeIndex).getValue();
var tax = sheet.getRange(r,taxIndex).getValue();
var invoicesRowsValues = [
["Owner Payable", netToOwner],
["Comission", comission],
["Service Fee", serviceFee],
["Taxes", tax]
];
var invoiceRow = ((r - 2) * invoicesRowsValues.length) + 1;
var valueRange = invoices.getRange(
invoiceRow,
1, 4, 2
)
valueRange.setValues(invoicesRowsValues)
var billsRowsValues = [
["Payable to Owners", netToOwner]
];
var billRow = ((r - 2) * billsRowsValues.length) + 1;
var valueRange = bills.getRange(billRow, 1, 1, 2)
valueRange.setValues(billsRowsValues)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment