Skip to content

Clear Excel Range

Type: excel-clear-range  ·  Package: Excel Activities v1.0.6  ·  Output: —

Clears the contents of a cell range or of the whole sheet. Use it to clean up old data before writing new data, or to empty a temporary work area. It can optionally clear the formatting too (colors, borders), not just the values.

It empties the cells of the given range (or, if you leave it out, the whole used range of the sheet). By default it clears only the contents — values and formulas — and keeps the formatting; with clearFormat = true it clears everything, formatting included. Accepts session or path — see the two modes.

  • Unlike the other write activities, the file and the sheet must exist.
  • On an empty sheet, without range, it does nothing and does not fail.
  • In fast mode it saves the file when done; in session mode, on Excel Save or Excel Close.

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.
rangestring—Range to clear, e.g. "A1:D20", or a single cell ("B3"). If omitted, the whole used range.
clearFormatboolfalseAlso clear the cells’ formatting. With false, only the contents.

This activity does not return a value.

MessageCause and fix
'session' or 'path' is required.Neither session nor path is set.
File not found.path does not exist. This activity does not create files.
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).
'…' is not A1 address or named range.range is not a valid address.
The process cannot access the file '…' because it is being used by another process.The file is open in another program when saving. Close it or retry with Retry.

Clear a results sheet before filling it again:

Excel Open path = asset("dashboard.xlsx") → output: workbook
Clear Excel Range session = workbook sheet = "Results"
Write Excel Sheet session = workbook sheet = "Results" data = newData
Excel Close session = workbook

Empty only the data block of a template, keeping titles and formatting:

Clear Excel Range path = "C:/reports/template.xlsx" sheet = "Detail" range = "A5:H500"