Forum Discussion
jhighland2
Feb 26, 2025Copper Contributor
Using a master list on one sheet for trackers on other sheets.
I'm sure I can accomplish the following using VBA, but I'm looking for a solution that will work in both the desktop and the web app. I'm not familiar yet with script code or using Power Automate, s...
NikolinoDE
Feb 28, 2025Gold Contributor
You can maybe achieve this in Excel for the Web using Office Scripts, which work in both the web and desktop versions of Excel.
function main(workbook: ExcelScript.Workbook) {
// Define sheet names
let masterSheet = workbook.getWorksheet("Master List");
let pendingSheet = workbook.getWorksheet("Pending");
// Define column indices (adjust as necessary)
let statusCol = 4; // Assuming "Status" is in column D (index 4)
let clientIdCol = 1; // Column A (index 1)
let lastNameCol = 2; // Column B (index 2)
let firstNameCol = 3; // Column C (index 3)
// Get used range of the Master List
let masterRange = masterSheet.getUsedRange();
let masterValues = masterRange.getValues();
// Get table on the Pending sheet
let pendingTable = pendingSheet.getTables()[0]; // Assumes there's a table on "Pending"
// Loop through Master List
for (let i = 1; i < masterValues.length; i++) { // Skip headers
let row = masterValues[i];
let status = row[statusCol - 1]; // Adjust for zero-based index
if (status === "Pending") {
let clientId = row[clientIdCol - 1];
let lastName = row[lastNameCol - 1];
let firstName = row[firstNameCol - 1];
// Check if Client already exists in the Pending table
let existingRows = pendingTable.getRange().getValues();
let exists = existingRows.some(r => r[0] === clientId); // Check if Client ID is already added
if (!exists) {
// Add new row to the Pending table
pendingTable.addRow(-1, [clientId, lastName, firstName]);
}
}
}
}
Backup your file, Script is untested.
To make the script run automatically whenever the Master List is updated:
Open Power Automate.
Create a new flow with the "When a row is modified in Excel" trigger.
Set the trigger to monitor the Master List.
Add an action: Run Office Script and select your script.
My answers are voluntary and without guarantee!
Hope this will help you.
- jhighland2Feb 28, 2025Copper Contributor
Thank you! I've been putting together VBA code to test the process on the desktop, so this gives me a great starting point for comparison and, ultimately, conversion!