I am trying to code a spreadsheet to automatically distribute payment to each person. Here is the link. I want it to distribute payment without deleting old payments. Here is the script I am using:
const payDay = () => {
// get spreadsheet
const ss = SpreadsheetApp.getActiveSpreadsheet()
// get Pay Tracking sheet
const paySheet = ss.getSheetByName('Pay Tracking')
// get names and amounts from M2
const namesAmounts = paySheet.getSheetValues(2, 13, 20, 2)
// add the amount to the corresponding sheet name
namesAmounts.forEach(data => {
// get sheet by name
const sheet = ss.getSheetByName(data[0])
// get last row in column D (= 4)
const lRow = sheet.getRange('N2:N').getValues().filter(String).length
// prepare data
const newData = [['deposit', data[1], new Date()]]
// prepare formats
const formats = [['@', '$0.00','dd/MM/yyyy']]
// set range
const range = sheet.getRange(lRow + 2, 4, 1, 3)
// set formats
range.setNumberFormats(formats)
// add new data
range.setValues(newData)
})
}
I am getting the error in the title whenever I try to run this script.
I tried changing the range being referenced a few different times. I was expecting it to find the name of each person and the amount they are being payed so it could be transferred to their individual sheets.