Google Sheets provides built-in functions for converting letters to their alphabet position numbers, and its Apps Script feature lets you create custom functions for more complex conversions. Whether you are building an educational worksheet, encoding messages with the A1Z26 cipher, or processing text data, this guide covers every method from basic formulas to automated batch processing.
Method 1: Basic CODE() Formula
The simplest way to convert a letter to its alphabet position in Google Sheets uses the same approach as Excel. The CODE() function returns a character's ASCII value, and subtracting 64 gives the alphabet position:
=CODE(UPPER(A1)) - 64This formula converts any single letter in cell A1 to its position (A=1 through Z=26). The UPPER() function normalizes the input so both "a" and "A" return 1.
Quick Reference
| Input (A1) | Formula Result | Explanation |
|---|---|---|
| A | 1 | CODE("A")=65, 65-64=1 |
| m | 13 | UPPER("m")="M", CODE("M")=77, 77-64=13 |
| Z | 26 | CODE("Z")=90, 90-64=26 |
Method 2: ARRAYFORMULA for Batch Processing
Google Sheets excels at batch operations with ARRAYFORMULA(). To convert an entire column of single letters at once:
=ARRAYFORMULA(CODE(UPPER(A1:A26)) - 64)Place this formula in cell B1 and it automatically fills B1:B26 with the corresponding position numbers. This is far more efficient than copying a formula down 26 rows.
Method 3: Converting Full Words
To convert each character of a word in a single cell, you need to split the text into individual characters. Google Sheets can do this with MID() and SEQUENCE():
=TEXTJOIN("-", TRUE,
ARRAYFORMULA(
CODE(UPPER(MID(A1, SEQUENCE(LEN(A1)), 1))) - 64
)
)For HELLO in A1, this produces 8-5-12-12-15. The SEQUENCE(LEN(A1)) generates row numbers 1 through 5, MID() extracts each character, and TEXTJOIN() concatenates with hyphens.
Method 4: REGEXREPLACE Approach
For a creative alternative that does not use CODE(), you can build a lookup with SUBSTITUTE() chains or use REGEXREPLACE() in combination with other functions. However, the CODE() method is cleaner and faster for most use cases.
Method 5: Custom Apps Script Function
Google Sheets allows you to create custom functions using Apps Script (JavaScript-based). Go to Extensions > Apps Script and paste:
/**
* Converts letters to their alphabet position numbers.
* @param {string} text The text to convert.
* @param {string} [sep="-"] Separator between numbers.
* @return {string} Position numbers joined by separator.
* @customfunction
*/
function LETTERNUM(text, sep) {
if (!text) return "";
sep = sep || "-";
return text
.toString()
.toUpperCase()
.split("")
.filter(function(c) { return c >= "A" && c <= "Z"; })
.map(function(c) { return c.charCodeAt(0) - 64; })
.join(sep);
}Save the script, return to your spreadsheet, and use it like any built-in function:
=LETTERNUM("Hello") → 8-5-12-12-15
=LETTERNUM("Hello", ",") → 8,5,12,12,15
=LETTERNUM("Hello World") → 8-5-12-12-15-23-15-18-12-4Adding Word Boundary Support
Enhance the custom function to preserve word boundaries:
function LETTERNUM_WORDS(text, sep, wordSep) {
if (!text) return "";
sep = sep || "-";
wordSep = wordSep || " / ";
return text
.toString()
.toUpperCase()
.split(/\s+/)
.map(function(word) {
return word
.split("")
.filter(function(c) { return c >= "A" && c <= "Z"; })
.map(function(c) { return c.charCodeAt(0) - 64; })
.join(sep);
})
.join(wordSep);
}=LETTERNUM_WORDS("Hello World")
→ 8-5-12-12-15 / 23-15-18-12-4Converting Numbers Back to Letters
Use the CHAR() function for the reverse operation:
=CHAR(A1 + 64) // Uppercase letter
=CHAR(A1 + 96) // Lowercase letterOr create a reverse Apps Script function:
function NUMTOLETTER(numbers, sep) {
if (!numbers) return "";
sep = sep || "-";
return numbers
.toString()
.split(sep)
.map(function(n) {
var num = parseInt(n.trim());
return (num >= 1 && num <= 26)
? String.fromCharCode(num + 64)
: "";
})
.join("");
}Practical Examples
Word Value Calculator
Calculate the sum of all letter positions (word value) for a word:
=SUMPRODUCT(
CODE(UPPER(MID(A1, SEQUENCE(LEN(A1)), 1))) - 64
)For "HELLO": 8 + 5 + 12 + 12 + 15 = 52.
Batch Processing Multiple Cells
Use ARRAYFORMULA with LETTERNUM across a range by entering the custom function once and dragging, or use the MAP function in Google Sheets:
=MAP(A1:A10, LAMBDA(cell, LETTERNUM(cell)))Error Handling
Wrap formulas in IFERROR() to handle empty cells and non-letter input gracefully:
=IFERROR(CODE(UPPER(A1)) - 64, "Not a letter")Prefer instant results? Try our free online A1Z26 Converter — no spreadsheet needed, works on any device.
Frequently Asked Questions
Can I use ARRAYFORMULA with a custom Apps Script function?
Custom functions in Apps Script do not automatically expand with ARRAYFORMULA(). However, you can modify the function to accept and return arrays, or use the MAP() function to apply a custom function to each cell in a range.
Why does my custom function show "Loading..."?
Apps Script custom functions run on Google's servers and may take a moment to execute. If it stays on "Loading..." indefinitely, check the Apps Script editor for syntax errors. Common issues include missing semicolons and unclosed parentheses.
Is CODE() in Google Sheets the same as in Excel?
Yes. Both return the ASCII value of the first character. Google Sheets CODE("A") returns 65, identical to Excel. The formula =CODE(UPPER(A1))-64 works identically in both applications.