{
  "category": "Information functions",
  "display_name": "SHEETS",
  "entry_kind": "built_in_function",
  "eval_api": {
    "method": "POST",
    "url": "https://handbook.dnacalc.com/api/eval"
  },
  "function_id": "FUNC.SHEETS",
  "implementation_state": {
    "answer_bank": null,
    "detail": "Recorded: 6 workbook cells.",
    "dnacalc_commit": "9e1884369a678158dd82d3d74188daf986995e87",
    "in_catalogue": true,
    "state": "matches",
    "state_label": "Matches every recorded Excel answer",
    "summary": "Matches all 6 recorded answers",
    "workbook_corpus": {
      "cells": 6,
      "matched": 6
    }
  },
  "implementations": [
    {
      "commit": "9e1884369a678158dd82d3d74188daf986995e87",
      "flavour": "excel-compatibility-candidate",
      "language": "Rust",
      "name": "CalcFunc",
      "own_code": [
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/host_facts.rs#L450-L450",
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/host_facts.rs#L329-L351"
      ],
      "repository": "https://github.com/DnaCalc/DnaCalc",
      "shared_code": [
        "catalogue/host_facts::first_cell",
        "catalogue/host_facts::cell_value",
        "catalogue/host_facts::column_letters",
        "catalogue/host_facts::facts",
        "catalogue/host_facts::qualified_sheet",
        "catalogue/host_facts::cell",
        "catalogue/host_facts::s_number",
        "catalogue/host_facts::info",
        "catalogue/host_facts::sheet",
        "format/cell_info::sections",
        "format/cell_info::tokens",
        "format/cell_info::is_date_time",
        "format/cell_info::date_time_class",
        "format/cell_info::places",
        "format/cell_info::number_class",
        "format/cell_info::classify",
        "ported/a1_refs::split_prefix",
        "ported/a1_refs::parse_cell_token",
        "ported/a1_refs::parse_column_token",
        "ported/a1_refs::parse_row_token",
        "ported/a1_refs::parse_a1_reference",
        "ported/address::address_name_character",
        "ported/address::address_name_is_reference",
        "ported/address::quote_sheet_text_if_needed"
      ],
      "source": "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/host_facts.rs#L450-L450",
      "state": "matches",
      "suite": null,
      "summary": "Matches all 6 recorded answers"
    }
  ],
  "json_url": "https://handbook.dnacalc.com/api/functions/FUNC.SHEETS.json",
  "name": "SHEETS",
  "notes": [],
  "schema": "efh.function-reference/v1",
  "section_order": [
    "what-it-does",
    "try-it",
    "quirks",
    "how-to-implement",
    "version-differences",
    "alternatives"
  ],
  "sections": {
    "alternatives": "\n### Relationships\n\n\n- **`SHEET([reference])`** is the index to `SHEETS`' count. Same module, same 2013 vintage, same\n  documented counting rule, routinely confused. Mnemonic: singular returns a position, plural\n  returns a quantity. Note also that `SHEET` accepts a text sheet name and `SHEETS` does not.\n- **`INFO(\"numfile\")`** counts worksheets across **all open workbooks**; `SHEETS()` counts within\n  the containing workbook. Two different numbers that are equal only when one file is open.\n- **`AREAS(reference)`** counts the areas in a multi-area reference the way `SHEETS` counts the\n  sheets in a 3-D one. They are the two cardinality functions over reference shape, they share an\n  implementation module, and together they characterise a reference's geometry.\n- **`ROWS` and `COLUMNS`** complete the set: `ROWS`, `COLUMNS`, `SHEETS` and `AREAS` are the four\n  functions that measure a reference instead of reading it.\n- **`CELL`, `INFO`, `ISFORMULA`, `FORMULATEXT`** are the other host-backed Information functions.\n\n\n",
    "how-to-implement": "\n### Notes for implementers\n\n\n1. **Count every sheet type**, including hidden, very hidden, chart, macro and dialog sheets. An\n   implementation that enumerates visible worksheets will under-report, silently and\n   workbook-dependently.\n2. **The argument's shape is the subject.** `SHEETS` must inspect the reference's sheet span, not\n   dereference it. A values-only path cannot implement this function at all.\n3. **Do not accept a text sheet name.** `SHEET` does; `SHEETS` does not. Adding it for symmetry\n   would be a divergence.\n4. **`SHEETS()` and `SHEETS(ref)` are different queries** — a workbook census and a span\n   measurement. Model them separately rather than passing a null reference into one code path.\n5. **Decide the multi-area and external-reference cases explicitly** and record them as decisions\n   awaiting evidence.\n\n\n",
    "quirks": "\n### Result and edge cases\n\n\nReturns a `Number` — a count, minimum `1` for any valid reference.\n\n- **An ordinary reference is `1`**, whether it is a single cell, an area, or a structured\n  reference; none of those spans sheets.\n- **A 3-D reference returns the span size**, counting every sheet between the endpoints in tab\n  order — which means hidden and chart sheets caught inside the span are counted too, by the\n  documented counting rule. A `Sheet1:Sheet3` span in a workbook with a hidden sheet between them\n  is `3`, not `2`, and the hidden sheet's cells participate in whatever the 3-D reference is\n  doing. That is a real workbook hazard, and `SHEETS` is how you detect it.\n- **A multi-area reference** spanning two sheets (`(Sheet1!A1, Sheet2!A1)`) — not addressed by\n  the documentation, not established here. Whether it counts 2, counts 1, or errors is open.\n- **An external-workbook reference** — whose sheet count is being returned, and does it differ\n  when the source workbook is closed? Not addressed, not established.\n- **`SHEETS` is not available in the object model.** Microsoft says so explicitly: \"SHEETS is not\n  available in the Object Model (OM) because the Object Model already includes similar\n  functionality.\" Automation code should read `Workbook.Sheets.Count`.\n\n\n\n### Errors\n\n\n- **`#REF!`** — documented: \"If reference is not a valid value, SHEETS returns the #REF! error\n  value.\"\n\nNote the difference from `SHEET`, which has two documented errors because it has two argument\nforms. `SHEETS` takes only references, so it has only the reference error. There is no `#N/A`\npath, because there is no name lookup to fail.\n\n`#NAME?` would arise before `SHEETS` runs, from an unresolvable defined name, in reference\nresolution ([coercion and lifting](../model/02-coercion-and-lifting.md)).\n\nArity failure (two or more arguments) is expected to be refused at formula entry rather than\nevaluated ([the call pipeline](../model/03-call-pipeline.md)).\n\n\n",
    "sources": "- Microsoft, \"SHEETS function\" —\n  <https://support.microsoft.com/en-us/office/sheets-function-770515eb-e1e8-45ce-8066-b557e5e4b80b>.\n  Read for this page: the description, the syntax, the `reference` argument description verbatim\n  including the omitted case, the counting remark, the `#REF!` condition, and the object-model\n  note.\n- Microsoft, \"SHEET function\" —\n  <https://support.microsoft.com/en-us/office/sheet-function-44718b6f-8b87-47a1-a9d6-b701c06cff24>.\n  Read for the sibling's argument forms and error pair, used in the comparison above.\n- Handbook, [the value universe](../model/01-value-universe.md) — the three-dimensional and\n  multi-area reference shapes this function measures.\n- Handbook, [the execution context](../model/04-execution-context.md) — the workbook state a\n  host query reads.\n\n\n",
    "version-differences": "No comparison between specific Excel builds is recorded here yet. This does not establish that all builds behave alike.",
    "what-it-does": "\n`SHEETS([reference])` returns **how many sheets** a reference spans, or — with the argument\nomitted — how many sheets the containing workbook has.\n\nMicrosoft's description is one line: \"Returns the number of sheets in a reference.\" The argument\ndescription supplies the omitted case: \"If Reference is omitted, SHEETS returns the number of\nsheets in the workbook that contains the function.\"\n\n*The quoted one-line description is Microsoft's text, from its support article <https://support.microsoft.com/en-us/office/sheets-function-770515eb-e1e8-45ce-8066-b557e5e4b80b>.*\n\nSo the function has two quite different jobs depending on whether you give it an argument, and\nthe two are worth separating:\n\n- **`SHEETS()`** — a workbook census. How many sheets exist.\n- **`SHEETS(ref)`** — a span measurement. How many sheets this reference reaches across, which is\n  `1` for an ordinary reference and larger only for a **three-dimensional** reference such as\n  `Sheet1:Sheet3!A1` ([the value universe](../model/01-value-universe.md) calls that a\n  three-dimensional reference shape). `SHEETS(Sheet1:Sheet3!A1)` is `3`.\n\nThat second job is the one the function was really added for. Before dynamic arrays, a 3-D\nreference was the only way a single argument could reach across sheets, and `SHEETS` is how a\nformula finds out that it did.\n\nThe counting rule is documented and is the same as `SHEET`'s: \"SHEETS includes all worksheets\n(visible, hidden, or very hidden) in addition to all other sheet types (macro, chart, or dialog\nsheets).\" A workbook showing three tabs can report `5`.\n\n\n### Arguments\n\n\n`reference` — **optional**, at most one. The published signature is `SHEETS([reference])`.\n\nUnlike `SHEET`, this function takes **only a reference**. It does not accept a sheet name as\ntext: there is no \"how many sheets does the sheet called X span\" question to ask. That asymmetry\nbetween the two siblings is easy to miss and is the source of most `SHEETS` errors.\n\nThe argument is a reference position, not a value position — the live reference must survive\nargument preparation, because the answer depends on the reference's *shape*, not on the values\nit designates.\n\nThe omitted form is a workbook-level query, not a caller-aware one in the coordinate sense: it\ndoes not depend on which cell the formula is in, only on which workbook. That is why the declared\nvolatility is `NonVolatile` — the answer changes only when a sheet is added or removed, which is\na structural edit.\n\n\n"
  },
  "signature": {
    "display": "SHEETS([reference])",
    "parameters": [
      {
        "description": null,
        "name": "reference",
        "optional": true,
        "repeats": false
      }
    ],
    "trailing_repeats": false
  },
  "sources": {
    "metadata": {
      "admission": {
        "label": "implemented",
        "reason": null
      },
      "arity": {
        "max": 1,
        "min": 0
      },
      "category": "Information functions",
      "classification": {
        "arg_preparation_profile": "RefsVisibleInAdapter",
        "coercion_lift_profile": "Custom",
        "determinism_class": "Deterministic",
        "error_collapse_profile": "None",
        "fec_dependency_profile": "RefOnly",
        "host_interaction_class": "WorkbookState",
        "kernel_signature_class": "Custom",
        "rich_value_usage": "RichBlind",
        "surface_fec_dependency_profile": "Composite",
        "thread_safety_class": "HostSerialized",
        "volatility_class": "NonVolatile"
      },
      "descriptions": {
        "long": null,
        "short": "Number of sheets in a reference or in the workbook",
        "short_source": "dna-calc-own"
      },
      "docs": {
        "english_description": "Returns the number of sheets in a reference",
        "microsoft_url": "https://support.microsoft.com/en-us/office/sheets-function-770515eb-e1e8-45ce-8066-b557e5e4b80b"
      },
      "entry_kind": "built_in_function",
      "localized_family_names": null,
      "localized_names": [
        {
          "locale": "ar-SA",
          "name": "SHEETS"
        },
        {
          "locale": "bg-BG",
          "name": "SHEETS"
        },
        {
          "locale": "cs-CZ",
          "name": "SHEETS"
        },
        {
          "locale": "da-DK",
          "name": "ARK.FLERE"
        },
        {
          "locale": "de-DE",
          "name": "SHEETS"
        },
        {
          "locale": "el-GR",
          "name": "SHEETS"
        },
        {
          "locale": "en-AU",
          "name": "SHEETS"
        },
        {
          "locale": "en-GB",
          "name": "SHEETS"
        },
        {
          "locale": "en-US",
          "name": "SHEETS"
        },
        {
          "locale": "es-ES",
          "name": "HOJAS"
        },
        {
          "locale": "et-EE",
          "name": "SHEETS"
        },
        {
          "locale": "fi-FI",
          "name": "TAULUKOT"
        },
        {
          "locale": "fr-FR",
          "name": "FEUILLES*"
        },
        {
          "locale": "he-IL",
          "name": "SHEETS"
        },
        {
          "locale": "hr-HR",
          "name": "SHEETS"
        },
        {
          "locale": "hu-HU",
          "name": "LAPOK"
        },
        {
          "locale": "id-ID",
          "name": "SHEETS"
        },
        {
          "locale": "it-IT",
          "name": "SHEETS"
        },
        {
          "locale": "ja-JP",
          "name": "SHEETS"
        },
        {
          "locale": "ko-KR",
          "name": "SHEETS"
        },
        {
          "locale": "lt-LT",
          "name": "SHEETS"
        },
        {
          "locale": "lv-LV",
          "name": "SHEETS"
        },
        {
          "locale": "nb-NO",
          "name": "ANTALL.ARK"
        },
        {
          "locale": "nl-NL",
          "name": "BLADEN"
        },
        {
          "locale": "pl-PL",
          "name": "ARKUSZE"
        },
        {
          "locale": "pt-BR",
          "name": "SHEETS"
        },
        {
          "locale": "pt-PT",
          "name": "FOLHAS"
        },
        {
          "locale": "ro-RO",
          "name": "SHEETS"
        },
        {
          "locale": "ru-RU",
          "name": "ЛИСТЫ"
        },
        {
          "locale": "sk-SK",
          "name": "SHEETS"
        },
        {
          "locale": "sl-SI",
          "name": "SHEETS"
        },
        {
          "locale": "sr-Latn-RS",
          "name": "LISTOVI"
        },
        {
          "locale": "sv-SE",
          "name": "ANTALBLAD"
        },
        {
          "locale": "th-TH",
          "name": "SHEETS"
        },
        {
          "locale": "tr-TR",
          "name": "SAYFALAR"
        },
        {
          "locale": "uk-UA",
          "name": "SHEETS"
        },
        {
          "locale": "vi-VN",
          "name": "SHEETS"
        },
        {
          "locale": "zh-CN",
          "name": "SHEETS"
        },
        {
          "locale": "zh-HK",
          "name": "SHEETS"
        },
        {
          "locale": "zh-TW",
          "name": "SHEETS"
        }
      ],
      "signature": {
        "display": "SHEETS([reference])",
        "parameters": [
          {
            "description": null,
            "name": "reference",
            "optional": true,
            "repeats": false
          }
        ],
        "trailing_repeats": false
      },
      "surface_name": "SHEETS",
      "version_marker": null,
      "xlcall": {
        "code": "587",
        "symbol": "xlfSheets"
      }
    },
    "microsoft": "https://support.microsoft.com/en-us/office/sheets-function-770515eb-e1e8-45ce-8066-b557e5e4b80b"
  },
  "try_it": {
    "formula": "=SHEETS()"
  },
  "url": "https://handbook.dnacalc.com/functions/SHEETS.html",
  "variants": [],
  "versions": []
}