Hi @Petra Ronald ;
First, thank you for your patience ;-)
I have now tested your script suggestion. I have adjusted only two small things in your script. I deliberately start the For loop at 1 instead of 0, because 0 are my column headers, where I do not need or want to set the hyperlink formula. Since I have a German Office 365 license, I must replace the comma between the link and the link description with a semicolon.
If I now start your script with these two changes, then the problem described before occurs again. All rows in column N get the formula of the last loop pass (see picture from my last post). This behavior can be explained by the description of the SetFormulaLocal command („If the range contains multiple cells, each cell in the given range will be updated with the input data”.).
With a little trick I could solve this now. I have extended the If loop within the For loop by "Else". If there is nothing in column L, then write a hyphen in column N in the same line. So that this does not get the blue color of a link again, I set the color back to black.
This is how it works now!
Here is the revised script:
function main(workbook: ExcelScript.Workbook)
{
let usedRange = workbook.getActiveWorksheet().getUsedRange();
let rowCount = usedRange.getRowCount();
let values = usedRange.getValues(); //I suggest getting the values for the entire range outside of the for loop to make your script run faster
for (var i = 1; i < rowCount; i++) { //is there any reason you are skipping the first row? the first row has index 0
if (values[i][11] != "") { //this would be how you get the value of a specific cell now since you got the values outside of the for loop
let hyperlinkDesc = values[i][11]; //this is the L column for each row assuming your used range starts in column A
let hyperlinkValue = values[i][12]; //this is the M column with the hyperlink value
usedRange.getCell(i, 13).setFormulaLocal('=HYPERLINK("' + hyperlinkValue + '"; "' + hyperlinkDesc + '")'); //setting column N
}
else
{
usedRange.getCell(i, 13).setValue("-");
usedRange.getCell(i, 13).getFormat().getFont().setColor(("Black"));
}
}
}
But now I can't really estimate how performant my loop extension is. In productive use I have Excel tables with about 500 rows. In the future, the script will be called via a Power Automate Flow, which will generate 4 Excel tables with 500 rows each. The flow itself does several other actions and now already takes over an hour.
If you tell me that now nothing more can be optimized here at the loop, then I would close my request herewith again and thank you already once for your support.
Regards
Herb