Office Scripts - Clear all filters (either slicer or table)

Sarah Otoka 1 Reputation point
2022-07-07T17:56:31.54+00:00

I just installed Office Scripts and am new to writing scripts. I need to clear all filters on my worksheet with a button. I found a script on-line and it won't run, shows no errors but isn't doing anything. I'm wondering if the script is missing something, can anyone help me?

Here's the script:
/**
* This script clears any applied criteria from the worksheet's autoFilter.
*/
function main(workbook: ExcelScript.Workbook) {
const currentSheet = workbook.getActiveWorksheet();

// Clear all the criteria currently applied to the autoFilter.
currentSheet.getAutoFilter().clearCriteria();
}

Microsoft 365 and Office Development Other
{count} votes

1 answer

Sort by: Most helpful
  1. Abdel Fattah Abdel Samie Ibrahim Morsy 0 Reputation points
    2023-06-15T09:06:54.5866667+00:00

    hi

    I had a script below run for active sheet , but how to run it to all sheets same time

    function main(workbook: ExcelScript.Workbook) {
    	let selectedSheet = workbook.getActiveWorksheet();
    	// Clear auto filter on selectedSheet
    	selectedSheet.getAutoFilter().clearCriteria();
    	// Set visibility of row(s) at range A:XFD on selectedSheet to false
    	selectedSheet.getRange("A:XFD").setRowHidden(false);
    	// Set visibility of column(s) at range A:XFD on selectedSheet to false
    	selectedSheet.getRange("A:XFD").setColumnHidden(false);
    }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.