-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathExtractURL.js
More file actions
23 lines (19 loc) · 754 Bytes
/
ExtractURL.js
File metadata and controls
23 lines (19 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function extractAndPasteLinks() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
// Get the number of rows with data in column B
var lastRow = sheet.getLastRow();
for (var i = 2; i <= lastRow; i++) {
var cell = sheet.getRange(i, 2);
var richTextValue = cell.getRichTextValue(); // Get the rich text value
if (richTextValue) {
var runs = richTextValue.getRuns(); // Get the runs (segments of text)
for (var j = 0; j < runs.length; j++) {
var url = runs[j].getLinkUrl(); // Get the URL from the text run
if (url) {
sheet.getRange(i, 3).setValue(url); // Paste the URL in Column C
break; // Stop after the first URL is found
}
}
}
}
}