By CS 26 年 2023 月 XNUMX 日星期日
張貼在 Excel
回复 2
0
觀看 3.3K
投票 0
Kutools 為我們製作了一個 Excel 電子表格,以避免重複輸入電子郵件地址。 但是我們丟失了這個電子表格。 所以我的問題是是否可以讓這個宏在谷歌表格上工作?
嗨,

很遺憾地告訴您,在 Excel 中有效的宏在 Google 表格中無效。 您必須在 Google 表格中重新創建它們。

阿曼達
·
1年前
·
0喜歡
·
0票
·
0 個評論
·
Kutools 為我們製作了一個 Excel 電子表格,以避免重複輸入電子郵件地址。 但是我們丟失了這個電子表格。 所以我的問題是是否可以讓這個宏在谷歌表格上工作?


請在 Google 表格中嘗試此 VBA。



function checkDuplicates() {
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();
var emailCol = 2; // Replace 2 with the column number of the email column

var emails = {};
var duplicates = [];

// Loop through the data and check for duplicates
for (var i = 1; i < data.length; i++) {
var email = data[i][emailCol];

if (email && email !== "" && emails[email]) {
// Duplicate found
duplicates.push(i + 1); // Add row number to duplicates array
} else {
// Add email to hash table
emails[email] = true;
}
}

if (duplicates.length > 0) {
// Display error message
var message = "Duplicate email(s) found on row(s): " + duplicates.join(", ");
SpreadsheetApp.getUi().alert(message);
}
}


·
1年前
·
0喜歡
·
0票
·
0 個評論
·
查看全文