apps-script-utils 2.1.1 Help

clearColumnsByConditional

function clearColumnsByConditional( target: GoogleAppsScript.Spreadsheet.Sheet | GoogleAppsScript.Spreadsheet.Range, predicate: ColumnPredicate, options: ColumnConditionalOptions | null | undefined = {} ): number;

clearRowsByConditional turned on its side: the contents go, the columns stay, so the letters of the columns after them do not change.

The sheet is read once and the clearing is grouped into consecutive blocks.

A sheet means its whole data range; a range means only the cells inside it, with the rest of the sheet neither read nor touched. Either way the predicate is given the position on the sheet, so a column keeps its real number.

Parameters

Parameter

Type

Description

target

GoogleAppsScript.Spreadsheet.Sheet \| GoogleAppsScript.Spreadsheet.Range

The sheet to work on, or the range to work within: only its cells are read, and only they are cleared.

predicate

ColumnPredicate

Receives the column's cells, its one-based position and — when headerColumn is set — the column keyed by the row names. Return true for the columns to act on.

options (optional) = {}

ColumnConditionalOptions \| null \| undefined

headerColumn names the column holding the row names, and keeps that column out of the candidates.

Returns

number — how many were affected.

Throws

Exception

Condition

InvalidSheetException

the first argument is neither a sheet nor a range.

IllegalArgumentException

the predicate is not a function, or the header position is not a positive integer.

Examples

In use

const sheet = SpreadsheetApp.getActiveSheet(); clearColumnsByConditional(sheet, (values) => values.every((cell) => cell === ""));

Within one block

const sheet = SpreadsheetApp.getActiveSheet(); // Only B2:Z100 is read, and only those cells are cleared. clearColumnsByConditional(sheet.getRange("B2:Z100"), (values) => values.every((cell) => cell === "") );

See also

Source

src/appsscript/sheet/clearColumnsByConditional.ts

23 September 2026

This documentation was generated with AI (Claude) from the library's source code.