By CS 在26年2023月XNUMX日星期日
张贴在 Excel
回复 2
0
观点 3.5
投票 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条评论
·
查看全文