Hi,
Apologies if this is not the right place to ask this question.
I'm automating a task in my report, however my script stops right after filer is done in the first table, and i'm not sure what to do next.
What i wanted from this script:
1. filter table employees to get only False value in column Help
2. Copy last visible cell from column Employee Basic Data name
3. Paste it at the end of table PT in sheet Planning in column Employee Basic Data name
4. copy section B2-B12 from sheet Lists
5. paste in the fist empty cell in table PT in sheet Planning in column Hours classification
6. Copy last non empty cell in table PT in sheet Planning in column Employee Basic Data name and paste it 11 times below
Below is my current script:
Apologies if this is not the right place to ask this question.
I'm automating a task in my report, however my script stops right after filer is done in the first table, and i'm not sure what to do next.
What i wanted from this script:
1. filter table employees to get only False value in column Help
2. Copy last visible cell from column Employee Basic Data name
3. Paste it at the end of table PT in sheet Planning in column Employee Basic Data name
4. copy section B2-B12 from sheet Lists
5. paste in the fist empty cell in table PT in sheet Planning in column Hours classification
6. Copy last non empty cell in table PT in sheet Planning in column Employee Basic Data name and paste it 11 times below
Below is my current script:
JavaScript:
function main(workbook: ExcelScript.Workbook) {
let employeesSheet = workbook.getWorksheet("Employees");
let planningSheet = workbook.getWorksheet("Planning");
let listsSheet = workbook.getWorksheet("Lists");
let Employees = workbook.getTable("Employees")
let PT = workbook.getTable("PT")
// Repeat until there is no "False" value in column "Help" in sheet "Employees"
while (Employees.getColumnByName("Help").getFilter().applyValuesFilter(["FALSE"])) {
// Get the last row in column "Help" in the "Employees" sheet
let lastRowHelp = Employees.getRange("Help").getUsedRange().getLastCell().getRowIndex();
{
// Copy the last cell from column "Employee Basic Data name"
let lastEmployeeName = Employees.getRange("Employee Basic Data name").getUsedRange().getLastCell();
lastEmployeeName.load("values");
// Get the last row in column "Employee Basic Data name" in the "Planning" sheet
let lastRowPlanning = PT.getRange("Employee Basic Data name").getUsedRange().getLastCell().getRowIndex();
// Paste the last employee name at the bottom of the "Employee Basic Data name" column in the "Planning" sheet
PT.getRange(`Employee Basic Data name[${lastRowPlanning + 1}]`).setValues(lastEmployeeName.values);
// Copy area B2:B12 from the "Lists" sheet
let hoursClassificationRange = listsSheet.getRange("B2:B12");
hoursClassificationRange.load("values");
// Get the last row in column "Hours classification" in the "Planning" sheet
let lastRowHoursClassification = planningSheet.getRange("Hours classification").getUsedRange().getLastCell().getRowIndex();
// Paste it in the last row of column "Hours classification" in the "Planning" sheet
planningSheet.getRange(`Hours classification[${lastRowHoursClassification + 1}]`).setValues(hoursClassificationRange.values);
// Copy the last nonempty cell from column "Employee Basic Data name" in the "Planning" sheet
let lastPlanningName = planningSheet.getRange("Employee Basic Data name").getUsedRange().getLastCell();
lastPlanningName.load("values");
// Paste it 11 times below
for (let i = 1; i <= 11; i++) {
planningSheet.getRange(`Employee Basic Data name[${lastRowPlanning + i + 1}]`).setValues(lastPlanningName.values);
}
}
}
}
Last edited by a moderator: