how to know which column is filtered

203 views
Skip to first unread message

Remicio Minami, Walter Daniel - PROV

unread,
Oct 23, 2023, 7:33:50 PM10/23/23
to Google Apps Script Community
Hi to all, is there a way to find which column is filtered?
Ive tried to find some hotkey combination to do this, but looks theres no way directly.

Any advice? i suppose by apps scripts i can do it.

Jim Willeke

unread,
Oct 24, 2023, 6:22:52 AM10/24/23
to Google Apps Script Community
Something like:
function getHiddenColumns(sheet) {
var data = sheet.getDataRange().getValues();
for (var d = 0; d < sheet.getLastColumn(); d++) {
// Row Index starts from 1
if (sheet.isColumnHiddenByUser(d + 1)) {
Logger.log('Column #' + d + ' is hidden - value: ' + data[0][d]);
continue;
}
// processRow(d)
}
}

Edward Friedman (Eddie)

unread,
Oct 25, 2023, 2:14:30 PM10/25/23
to Google Apps Script Community
Does this get at what your're trying to do? It returns an array with the positions of any columns that have filter criteria applied to them.

function getFilteredColumns(sheet) {
  //make a blank array to hold the column positions with applied filter criteria
  const filteredColumns = [];

  //get the filter on the sheet
  const filter = sheet.getFilter();

  //if there is no filter on the sheet, return the empty array
  if (!filter) {
    return filteredColumns;
  }

  //loop through all of the columns to see if there are any filter criteria
  //  if there are filter criteria, then add the column position to the array
  for (let col=1;col<=sheet.getLastColumn();col++) {
    if (filter.getColumnFilterCriteria(col)) {
      filteredColumns.push(col);
    }
  }

  //return the array containing the column positions of each column
  //  with filter criteria applied
  return filteredColumns;
}
Reply all
Reply to author
Forward
0 new messages