Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,715 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I need my code to run only in AC5:AC column but it runs in every cell, not sure what the problem is, where's my code:
function main(workbook: ExcelScript.Workbook) {
// Get the specific sheet in the workbook.
let sheet: ExcelScript.Worksheet = workbook.getWorksheet("DAILY");
// Get the range of cells in column AC.
let usedRange: ExcelScript.Range = sheet.getRange("AC:AC");
// Get the used range of cells in column AC.
let columnUsedRange: ExcelScript.Range = usedRange.getUsedRange(true);
// Log the range's address to the console.
console.log(columnUsedRange.getAddress());
// Get the current date and time.
let date: Date = new Date();
let dateTime: string = date.toLocaleString();
// Get the username
let username: string = "user name"; // Use a default value for username
console.log(`The current date and time is ${dateTime}`);
console.log(`The current username is ${username}`);
// Get the active cell
let activeCell: ExcelScript.Range = workbook.getActiveCell();
console.log(`The active cell's address is: ${activeCell.getAddress()}`);
// Check if the active cell is in column AC
if (activeCell.getColumn(29) === usedRange.getColumn(29)) {
// Get the cell to the right of the active cell.
let rightCell: ExcelScript.Range = activeCell.getOffsetRange(0, 1);
let rightCellValue: string = rightCell.getValue().toString();
// Set the value of the right cell to the concatenation of the date and time, the username, the cell's value, and the current value of the right cell after it.
rightCell.setValue(`${dateTime} (${username}) > FINAL COMMENT: ${activeCell.getValue()}\n${rightCellValue}`);
}
}