[SOLVED] Reset all filters in a given range

43 views
Skip to first unread message

Dirk

unread,
Oct 9, 2020, 10:44:27 AM10/9/20
to google-apps-sc...@googlegroups.com
I use the following code to reset all filters in Google Sheets in a given range. The problem is, that it takes too long. I guess, there is a better way to do this. I do not want to remove the filters. I simply want them to reset so that all rows will appear.

var Test = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Test');
for (var i=9; i<38; i++) {
 
Test.getRange('I9:AO8').getFilter().removeColumnFilterCriteria(i);
 
}}

Can you help?

Meanwhile I know the solution:

function resetfilters() {
 
var Test = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Test');
 
var lastrow_Test = Test.getLastRow();


 
var checkfilter = Test.getRange('I9:AO9').getFilter() != null;
 
 
if (checkfilter)
 
{
   
Test.getRange('I9:AO9').getFilter().remove();
   
Test.getRange('I9:AO'+lastrow_Test).createFilter();
 
}}



Tanaike

unread,
Oct 9, 2020, 9:24:49 PM10/9/20
to Google Apps Script Community
In your case, for example, how about removing the filter and creating new filter for the range of "Test.getRange('I9:AO8')"?

2020年10月9日金曜日 23:44:27 UTC+9 Dirk:

Dirk

unread,
Oct 10, 2020, 4:50:07 AM10/10/20
to Google Apps Script Community
How can I set a new filter for a range? According to my research there is no way to do this!?

Tanaike

unread,
Oct 10, 2020, 8:19:52 PM10/10/20
to Google Apps Script Community
In your script, the filters of the basic filter are removed while the basic filter is left with no filters. So in this case, I thought that your script is the same with "range.getFilter().remove(); range.createFilter();". How about this?

2020年10月10日土曜日 17:50:07 UTC+9 Dirk:

Dirk

unread,
Oct 12, 2020, 3:48:51 AM10/12/20
to Google Apps Script Community
This is not working.

Tanaike

unread,
Oct 12, 2020, 4:17:13 AM10/12/20
to Google Apps Script Community
Thank you for replying. About "This is not working.", I deeply apologize my comment was not useful for your situation.


2020年10月12日月曜日 16:48:51 UTC+9 Dirk:

Dirk

unread,
Oct 12, 2020, 4:20:00 AM10/12/20
to Google Apps Script Community
No worries. The first parts works but "createFilter()" is not working. But thank you anyway for your help!

Dirk

unread,
Oct 12, 2020, 9:48:22 AM10/12/20
to google-apps-sc...@googlegroups.com
Thank you for your help! Meanwhile I know what I have done wrong. I have posted the solution directly in the posting start.


Am Montag, 12. Oktober 2020 10:17:13 UTC+2 schrieb Tanaike:
Reply all
Reply to author
Forward
0 new messages