Skip to main content

SHEETS

Returns the number of sheets in a reference.

Syntax

expression.SHEETS(arg1);

expression - A variable that represents a ApiWorksheetFunction class.

Parameters

NameRequired/OptionalData typeDefaultDescription
arg1OptionalApiRange | ApiNameA reference for which the number of sheets will be returned. If omitted the number of sheets in the workbook containing the function is returned.

Returns

number

Example

Return the number of sheets in a reference in a spreadsheet.

// The SHEETS function counts all sheets in the current workbook.

// Add additional sheets and return their total count.

Api.AddSheet("Sheet2")
Api.AddSheet("Sheet3")

// Get the number of sheets
let func = Api.WorksheetFunction;
let result = func.SHEETS();
const worksheet = Api.GetActiveSheet();
worksheet.GetRange("C3").SetValue(result);