Math and trigonometry functions

SEQUENCE

Matches all 52 recorded answers

Recorded: 52 workbook cells. How we measure this · See the Rust code

Local names in 40 languages
LanguageName in Excel
ArabicSEQUENCE
BulgarianSEQUENCE
CzechSEQUENCE
DanishSEKVENS
GermanSEQUENCE
GreekSEQUENCE
English (Australia)SEQUENCE
English (United Kingdom)SEQUENCE
English (United States)SEQUENCE
SpanishSECUENCIA
EstonianSEQUENCE
FinnishSEKVENSSI
FrenchSEQUENCE
HebrewSEQUENCE
CroatianSEQUENCE
HungarianSORSZÁMLISTA
IndonesianSEQUENCE
ItalianSEQUENCE
JapaneseSEQUENCE
KoreanSEQUENCE
LithuanianSEQUENCE
LatvianSEQUENCE
NorwegianSEQUENCE
DutchVOLGORDE
PolishSEKWENCJA
Portuguese (Brazil)SEQUENCE
Portuguese (Portugal)SEQUÊNCIA
RomanianSEQUENCE
RussianПОСЛЕД
SlovakSEQUENCE
SlovenianSEQUENCE
Serbian (Latin)SEKVENCE
SwedishSEKVENS
ThaiSEQUENCE
TurkishSIRALI
UkrainianSEQUENCE
VietnameseSEQUENCE
Chinese (Simplified)SEQUENCE
Chinese (Hong Kong)SEQUENCE
Chinese (Traditional)SEQUENCE

Names from Microsoft's support site.

What it does

SEQUENCE(rows, [columns], [start], [step])

SEQUENCE(rows, [columns], [start], [step]) creates a rectangular array of regularly spaced numbers. Optional arguments default to one. Microsoft also permits omitting rows when at least one other argument is supplied; the missing row count then defaults to one.

Try it

Input cells (optional)

Example: {"B2": 3, "B3": 4}. A1 holds the formula. Other cells need values before a formula can read them.

Enter a formula, then calculate.

Runs locally in your browser with OneCalc. Its answer may differ from Excel. Use English function names and commas between arguments.

=SEQUENCE(2,3,10,2) spills these two rows:

Column 1Column 2Column 3
101214
161820

The sequence continues across the first row before moving to the second. =SEQUENCE(,3,5,2) produces one row, 5,7,9. A negative step descends, while a zero step repeats the start value.

Quirks

The output needs enough free worksheet cells to spill. The function’s array result and the workbook’s placement decision are separate: a correct two-by-three array can still encounter a spill obstruction. Microsoft documents limited support for dynamic arrays linked across workbooks; closing the source workbook can give #REF! when the link refreshes.

The current numeric implementation accepts positive integer dimensions. A zero dimension gives #CALC!; a negative or fractional dimension gives #VALUE!. Omitted or blank arguments take their defaults. These error choices come from the implementation, since the opened Microsoft function page does not enumerate those dimension errors.

How to implement

  1. Prepare all four arguments, preserving formed worksheet errors. Apply the defaults before dimension checks; omission and numeric zero are different cases.
  2. Require finite, positive integer row and column counts. Check their product for overflow and against the host’s output limit before allocating.
  3. For zero-based output index i, compute start+i*step with a multiply followed by an add. Store it at row i div columns, column i mod columns.
  4. Return an array with the requested shape. The workbook host checks its spill destination.

This is the current code’s direct-index calculation. Do not silently replace it with repeated previous+step: accumulated rounding can change the sequence. For example, the current route for SEQUENCE(1,3,10000000000000000,1) gives 10000000000000000, 10000000000000000, 10000000000000002; repeated binary64 addition of one would stay at the first value. This distinguishes two implementable algorithms, not an identified arithmetic route for every Excel build.

Rust code

Show the CalcFunc source of this function

Quoted from the public repository DnaCalc/DnaCalc, crates calc-func and calc-fml, at commit 9e1884369a67. Comments are the source's own. A kernel shared with other functions appears once, on its module page.

SEQUENCE · 3 lines · calc-func/src/catalogue/arrays.rs on GitHub
1 sequence_fn "SEQUENCE" (1, 4) [V "rows", V "columns", V "start", V "step"] resume sequence_resume => sequence_task; |s, a, sv| {
    result(s, k::eval_sequence_prepared(a))
}
sequence_task · 10 lines · calc-func/src/catalogue/arrays.rs on GitHub
fn sequence_task(
    site: &Site<'_>,
    args: &[CalcValue],
    _: &mut EvalServices<'_>,
) -> Step<Box<dyn crate::call::KernelTask>> {
    Ok(Box::new(SequenceTask(result(
        site,
        k::SequenceWork::new(args),
    )?)))
}
new · 6 lines · calc-func/src/ported/dynamic_array_reshape_family.rs on GitHub
fn new(arg: &'a CalcValue) -> Self {
    match arg.core_ref() {
        CoreRef::Array(array) => Self::Array(array),
        _ => Self::Scalar(scalar_cell(arg)),
    }
}
SequenceWork::new · 55 lines · calc-func/src/ported/dynamic_array_reshape_family.rs on GitHub
pub(crate) fn new(args: &[CalcValue]) -> Result<Self, DynamicArrayReshapeEvalError> {
    // Fn2 roots164/165: formed argument errors keep their order before a
    // dimension-derived error. Arrays and callable values keep their own route.
    for value in args {
        if value.callable_value().is_none()
            && let CoreRef::Error(code) = value.core_ref()
        {
            return Err(DynamicArrayReshapeEvalError::Preparation(
                CoercionError::WorksheetError(code),
            ));
        }
    }
    fn dimension(arg: Option<&CalcValue>) -> Result<usize, DynamicArrayReshapeEvalError> {
        let raw = match arg {
            None => return Ok(1),
            Some(value) if matches!(value.core_ref(), CoreRef::Missing | CoreRef::Empty) => {
                return Ok(1);
            }
            Some(value) => coerce_prepared_to_number(value)
                .map_err(DynamicArrayReshapeEvalError::Preparation)?,
        };
        if raw == 0.0 {
            return Err(DynamicArrayReshapeEvalError::EmptyArrayResult);
        }
        if !raw.is_finite() || raw < 0.0 || raw.fract() != 0.0 {
            return Err(DynamicArrayReshapeEvalError::InvalidCount);
        }
        Ok(raw as usize)
    }
    fn scalar(arg: Option<&CalcValue>) -> Result<f64, DynamicArrayReshapeEvalError> {
        match arg {
            None => Ok(1.0),
            Some(value) if matches!(value.core_ref(), CoreRef::Missing | CoreRef::Empty) => {
                Ok(1.0)
            }
            Some(value) => coerce_prepared_to_number(value)
                .map_err(DynamicArrayReshapeEvalError::Preparation),
        }
    }
    let rows = dimension(args.first())?;
    let cols = dimension(args.get(1))?;
    let start = scalar(args.get(2))?;
    let step = scalar(args.get(3))?;
    let count = ArrayShape { rows, cols }
        .cell_count()
        .ok_or(DynamicArrayReshapeEvalError::InvalidCount)?;
    Ok(Self {
        rows,
        cols,
        start,
        step,
        count,
        cells: Vec::new(),
    })
}
SequenceWork::advance · 12 lines · calc-func/src/ported/dynamic_array_reshape_family.rs on GitHub
pub(crate) fn advance(
    &mut self,
    elements: usize,
) -> Option<Result<CalcValue, DynamicArrayReshapeEvalError>> {
    let end = self.cells.len().saturating_add(elements).min(self.count);
    for idx in self.cells.len()..end {
        self.cells
            .push(CalcValue::number(self.start + (idx as f64) * self.step));
    }
    (end == self.count)
        .then(|| build_array(self.rows, self.cols, std::mem::take(&mut self.cells)))
}
eval_sequence_prepared · 7 lines · calc-func/src/ported/dynamic_array_reshape_family.rs on GitHub
pub fn eval_sequence_prepared(
    args: &[CalcValue],
) -> Result<CalcValue, DynamicArrayReshapeEvalError> {
    SequenceWork::new(args)?
        .advance(usize::MAX)
        .expect("unlimited sequence completes")
}

Kernels shared with other functions

Argument and result plumbing

No implementation has been published with a Handbook test suite for this function.

Version differences

No same-input comparison between named Excel builds is recorded for this function here. The documented behaviour below is not a measurement of every Excel release.

Alternatives

MAKEARRAY computes each entry from coordinates; RANDARRAY generates random entries; SCAN returns intermediate accumulator values.

Named variants

No named variants are recorded yet.

Suggest a correction or contribute an implementation · For agents