Skip to main content

Delete comments

Deletes comments from a specified range of cells in the active worksheet.

(function () {
// Get the active worksheet.
let sheet = Api.GetActiveSheet();

// Define sheet range and comment text to delete.
let totalRows = 100;
let totalCols = 100;
let targetCommentText = "Comment 1";

// Loop through the specified range of rows and columns.
for (let row = 0; row <= totalRows; row++) {
for (let col = 0; col <= totalCols; col++) {
let cell = sheet.GetRangeByNumber(row, col);
let comment = cell.GetComment();

// Delete the comment if it matches the predefined text.
if (comment && comment.GetText() === targetCommentText) {
comment.Delete();
}
}
}
})();

Methods used: GetActiveSheet, GetRangeByNumber, GetComment, GetText, Delete

Result

DeleteComments DeleteComments