Skip to content

Referencing and writing to worksheet cells from Jet commands

Use Jet’s cell-reference operators to read data from cells, write values back, or place formulas — all from the Command Editor or inside a .jt script segment. This is the scripting-side complement to the formula bar: the formula bar lets you type expressions into cells; these operators let a running command reach out to cells.

# references the active worksheet. #A1 is cell A1, #B2:B101 is a range, #D2 is cell D2. A single # at the start of a range is enough — you don’t repeat it before the second endpoint.

These operators are part of Jet’s syntax. Switch the Command Editor to Jet before using them. If Python or R is the active language and you want to manipulate cells programmatically, switch to Jet for that work — or place the cell-reference commands in a # %% jet segment of a mixed-language script.

x = #B2:B101;

Reads the range B2:B101 into a Jet variable x.

#J1 = mean(#B2:B101)

Reads B2:B101, computes the mean using Jet’s mean, writes the result to J1.

Assigning a string to a cell mirrors typing into the formula bar:

  • A string that starts with = becomes a formula.
  • A string without a leading = becomes literal cell text.
#J2 = "=AVERAGE(B2:B101)"

Writes a formula to J2 — exactly as if you had clicked J2 and typed =AVERAGE(B2:B101) in the formula bar. The cell shows the computed average and recomputes whenever the B column changes.

#J3 = "=py::numpy.std(B2:B101)"

Writes a Python formula to J3 — the cell uses Python’s numpy.std to compute the standard deviation. The py:: qualifier routes it to Python, just as it would in the formula bar.

Important distinction: the # operator is for Jet command syntax — outside of formula text. Inside a formula string, cell references like B2:B101 already refer to the active worksheet by default. So #J1 = mean(#B2:B101) uses # (it’s Jet code), but #J2 = "=AVERAGE(B2:B101)" doesn’t need # inside the quotes (the part inside the quotes is formula-bar text).

When the auto-detection (leading = → formula, otherwise text) isn’t what you want, use the explicit wrappers:

#J4 = _f("AVERAGE(B2:B101)")

Same end result as #J2 = "=AVERAGE(B2:B101)" — the leading = is optional inside _f() because the wrapper itself signals “this is a formula.” _f() is useful when the formula text comes from a variable and you want to be unambiguous.

#J5 = _t("=AVERAGE(B2:B101)")

Writes the literal text =AVERAGE(B2:B101) to J5 — no formula evaluation. The cell displays the formula source as a string. _t() is useful when you want a string that happens to start with = to stay as text: a label, a header, a piece of documentation that shows a formula without computing it.

The leading underscores in _f() and _t() avoid collisions with user-defined functions named f or t.

#L1 = "Mean"; #M1 = mean(#B2:B101);
#L2 = "Std"; #M2 = std(#B2:B101);
#L3 = "Count"; #M3 = length(#B2:B101);
for i = 2:101
#("E" + string(i)) = _f("B" + string(i) + " * 1.8 + 32");
end

Fills E2:E101 with Fahrenheit-conversion formulas that reference the corresponding B-column Celsius values.

In a .jt mixed-language script, use a Jet segment for cell I/O and other segments for computation:

# %% jet
temps = #B2:B101;
# %% python
import numpy as np
result = np.percentile(temps, [25, 50, 75])
# %% jet
#L1 = "Q1"; #M1 = result(1);
#L2 = "Med"; #M2 = result(2);
#L3 = "Q3"; #M3 = result(3);