Aller au contenu
GridBelt
  • Test Excel
  • Exercices
  • Programmes
  • Tarifs
Se connecter
Commencer le test gratuit
  • Test Excel
  • Exercices
  • Programmes
  • Tarifs
Se connecterCréer un compte
Commencer le test gratuit
GridBelt

Entraînez-vous sur Excel dans votre navigateur.

Test Excel

  • Niveau 1 : Débutant
  • Niveau 2 : Intermédiaire
  • Niveau 3 : Expert
  • Test Excel en 7 jours
  • Classement
  • Test Excel en entretien d’embauche
  • Évaluation Excel d’Indeed

Exercices

  • Tous les exercices
  • Programmes
  • Pour débutants

Guides

  • Formules Excel
  • Raccourcis Excel

Entreprise

  • À propos
  • Tarifs
  • Comment nous corrigeons

© GridBelt. Tous droits réservés.

  • Politique de confidentialité
  • Conditions d’utilisation
  • Politique de remboursement

Excel est une marque commerciale de Microsoft Corporation. Indeed, TestGorilla, SHL et les autres marques sont la propriété de leurs détenteurs respectifs. GridBelt est un site d’entraînement indépendant ; il n’est affilié ni à Microsoft, ni à TestGorilla, ni à SHL, ni à Indeed, et n’est ni cautionné ni sponsorisé par ces sociétés.

  1. Exercices
  2. /
  3. IF function

SWITCH and IFS practice: region names from codes on 200 shipments

  • Expert
  • ~8 min
  • IF function

Énoncé en anglais

The warehouse system exports 200 October shipments with a one-letter region code in column B: N, S, E, W and C stand for North, South, East, West and Central. The dashboard needs the full names, and 6 rows carry codes the mapping does not know — a blank, a typo like "NE" — which must read Unknown rather than an error, so they can be sent back for correction. Translate the codes with one formula.

Ce que vous devez faire

  1. 1Click F2. The code to translate is in B2.
  2. 2Type =SWITCH(B2, then list the pairs code, name — "N","North","S","South","E","East","W","West","C","Central" — and finish with the default "Unknown" as the last argument before the closing bracket.
  3. 3Press Enter and fill F2 down to F201 (double-click the fill handle, or select F2:F201 and press Ctrl+D / ⌘D).
  4. 4Find a row with an unknown code (an empty code or "NE"): it must read Unknown. Then click Check (Ctrl+Enter / ⌘+Return). IFS with a TRUE,"Unknown" catch-all is accepted as well.

Cellules de réponse

Correction

Saisissez votre formule dans la grille, appuyez sur Enter, puis cliquez sur Vérifier. Nous corrigeons la valeur de chaque cellule de réponse et la formule qui la produit.

Tâches

  1. Non vérifiéIn F2, return the region name for the code in B2 — N North, S South, E East, W West, C Central, anything else "Unknown" — with SWITCH or IFS, then fill it down to F201.

Ordinateur recommandé pour les tâches dans la feuille de calcul. La feuille défile à l’intérieur de ce cadre.

StartInsertFormulasDataView
A1fxPréparation de votre classeur…
A
B
C
D
E
F
G
H
I
J
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Sheet1

Saisissez votre formule dans la feuille, puis vérifiez.

À propos de cet exercice

Un jeu de données de 200 lignes sur une feuille, une cellule de réponse, environ 8 minutes. Corrigé dans votre navigateur : la valeur et la formule qui la produit, avec des indications sur la correction à apporter.

Comment le résoudre

  • F2=SWITCH(B2,"N","North","S","South","E","East","W","West","C","Central","Unknown")

SWITCH takes one expression — the code in B2 — and a list of value/result pairs: when the code equals "N" it returns "North", when it equals "S" it returns "South", and so on. An odd final argument is the default, returned when nothing matched, which is how the blank and mistyped codes become Unknown instead of an error. IFS does the same with explicit tests (B2="N", B2="S", …) and a TRUE,"Unknown" pair at the end; both read far better than four nested IFs.

Pitfall 1: forgetting the default — SWITCH without it returns #N/A for the unmapped codes, and IFS without the TRUE branch does the same, which then poisons every COUNTIF and pivot built on the column. Pitfall 2: SWITCH only tests equality against one expression; for ranges (>=) you need IFS or a lookup. Comparisons are case-insensitive ("n" matches "N") but a trailing space in the code is a different value — TRIM(B2) when the export is dirty. Pitfall 3: a mapping typed into a formula is hidden from the people who maintain the codes; once the list has more than a handful of entries, put it in a two-column table and use XLOOKUP(B2,codes,names,"Unknown") or VLOOKUP with IFERROR. Version notes: SWITCH and IFS exist in Excel 2019, 365 and the web app; in Excel 2016 and earlier use nested IF or CHOOSE(MATCH(B2,{"N","S","E","W","C"},0),…) wrapped in IFERROR. Performance: all variants are trivial at 200 rows; the lookup version is also the fastest to recalculate once the sheet grows to hundreds of thousands of rows.

Autres méthodes valables

  • =IFS(B2="N","North",B2="S","South",B2="E","East",B2="W","West",B2="C","Central",TRUE,"Unknown") — IFS with a catch-all TRUE branch
  • =IFERROR(XLOOKUP(B2,{"N","S","E","W","C"},{"North","South","East","West","Central"}),"Unknown") — Excel 365; a lookup against inline arrays (not accepted by this task, which asks for SWITCH or IFS)
  • =IF(B2="N","North",IF(B2="S","South",IF(B2="E","East",IF(B2="W","West",IF(B2="C","Central","Unknown"))))) — the nested-IF version this exercise replaces

Erreurs fréquentes

Leaving out the default value: =SWITCH(B2,"N","North",…,"C","Central") returns #N/A on the 6 rows with an unknown code, and the first of those is the cell the grader names.

Comment nous corrigeons

Toute formule qui produit le bon résultat est acceptée, sauf si la tâche nomme une fonction : une autre fonction rapporte alors la moitié des points. Nous comparons les valeurs avec une petite tolérance et ignorons la casse et les espaces dans le texte. Un nombre correct saisi à la main au lieu d’une formule rapporte la moitié des points. Les tâches sur plusieurs cellules rapportent tous les points avec 100 % de cellules justes, la moitié à partir de 50 %. Lorsque c’est pertinent, nous modifions aussi une cellule d’entrée sur une copie de votre feuille et vérifions que votre formule suit.

Réponses calculées selon les règles d’Excel 365 et vérifiées dans notre correcteur le 16 novembre 2026. Auteur : GridBelt team.

Dans ces programmes

  • Excel for Data AnalystsJour 10

Exercices associés

  • Commission tiers with nested IF, IFS or a lookupIntermédiaire, ~8 min
  • Pass or Fail with IFDébutant, ~4 min
  • Orders per region and month with COUNTIFSIntermédiaire, ~7 min

Référence de la fonction

Documentation officielle

Exercice suivant

Orders per status with COUNTIF