Open Excel and click Automate in menu -> New Script, Customize below script and paste in the Code Editor:
```
function main(workbook: ExcelScript.Workbook) {
// Get the active worksheet
let ws = workbook.getActiveWorksheet();
// Find the last row with data in column C
let lastRowC = ws.getRange("C:C").getLastCell().getRowIndex();
// Loop through all the rows
for (let i = 1; i <= lastRowC; i++) {
// Get the cells in column C and BP
let cellC = ws.getCell(i, 2); // 2 is the correct column index for C
let cellBP = ws.getCell(i, 67); // 67 is the correct column index for BP
// Replace the value in column BP with the value in column C
// cellBP.setValue(cellC.getValue())
try {
// Set the value in column BP to "Y202309"
cellBP.setValue("2023-09");
} catch (error) {
console.error(`Error setting value in BP for row ${i}: ${error}`);
};
}
}
```And click Run, then monitor if the column is updated.
No comments:
Post a Comment