Skip to content

Get Excel Used Range

Type: excel-get-used-range  ·  Package: Excel Activities v1.0.6  ·  Output: Dictionary

Returns the dimensions of the area that holds data in a sheet (the “used range”). It tells you how many rows and columns there are and where they start and end, without reading all the content. Useful to know the size of the data before processing it, or to build a dynamic range.

It computes the smallest rectangle that covers every cell with content (values or formulas) and returns a dictionary with its metrics. Cells that only have formatting (color, borders) don’t count. Accepts session or path — see the two modes.

Read-only: in fast mode it does not modify the file.

None — but you must set session or path (or be inside the body of an Excel Open).

ParameterTypeDefaultDescription
sessionZoanExcelSession—Excel Open session (instead of path).
pathstring—Path to the .xlsx (required if there is no session). The file must exist.
sheetstring | int—Sheet name or 1-based index. If omitted, the first sheet.

Returns a Dictionary with these exact keys:

KeyTypeDescription
addressstringAddress of the used range, e.g. "A1:F120" (no $ or sheet name).
rowsintNumber of rows in the range.
columnsintNumber of columns in the range.
firstRowintNumber of the first row (1-based).
firstColumnintNumber of the first column (1-based: A = 1).
lastRowintNumber of the last row.
lastColumnintNumber of the last column.

Empty sheet: address is null and every other key is 0 (it also logs a warning). Check it with dim["rows"] == 0.

MessageCause and fix
'session' or 'path' is required.Neither session nor path is set.
File not found.path does not exist.
There isn't a worksheet named '…'.No sheet has that name.
There isn't a worksheet associated with that position.The sheet index does not exist (or the name is just a number and was taken as an index).
Get Excel Used Range path = asset("data.xlsx") → output: dim
Log message = "The sheet has " + dim["rows"] + " rows and " + dim["columns"] + " columns"

Read only columns A to C, down to the last row with data:

Get Excel Used Range path = asset("data.xlsx") sheet = "Sales" → output: dim
Read Excel Range path = asset("data.xlsx") sheet = "Sales" range = "A1:C" + dim["lastRow"] → output: sales