Modern spreadsheet workflows frequently interact with external web APIs, database lookups, map locations, and automated query links. However, URLs cannot contain raw spaces, ampersands, quotation marks, or non-ASCII characters without causing syntax errors or broken requests. In Microsoft Excel, converting standard text into compliant, percent-encoded URL strings is handled natively by the ENCODEURL function. This tutorial explains how to use ENCODEURL in Microsoft Excel to format query parameters and construct dynamic hyperlinks for API requests.
What is URL Encoding and Why is it Necessary?
Uniform Resource Locators (URLs) conform to strict RFC 3986 character guidelines. Certain characters have reserved meanings in web communication:
?indicates the start of a query string.&separates key-value parameters.=assigns a parameter value.- Spaces and punctuation (like
#,/,+, and%) must be replaced with a percent sign (%) followed by their two-digit hexadecimal ASCII representation (for example, a space becomes%20).
If you concatenate text fields containing spaces or symbols directly into web links without encoding, destination web servers will truncate the request or return a 400 Bad Request error.
Syntax and Parameters
The syntax for the ENCODEURL function in Excel is straightforward:
=ENCODEURL(text)
Parameters
text(Required): The text string, cell reference, or concatenated expression you want to convert into a URL-encoded string.
Step-by-Step Practical Examples in Microsoft Excel
Example 1: Encoding Simple Search Strings and Addresses
Suppose cell A2 contains the search query: Coffee & Pastries: London.
- Select an adjacent cell, such as
B2. - Enter the formula:
=ENCODEURL(A2) - Excel outputs:
Coffee%20%26%20Pastries%3A%20LondonNotice how spaces are converted to
%20, the ampersand (&) becomes%26, and the colon (:) becomes%3A.
Example 2: Constructing Dynamic Google Maps Navigation Links
You can combine ENCODEURL with the HYPERLINK function to generate interactive map links for client addresses listed in your spreadsheet:
- Assume cell
A2contains the street address:10 Downing St, London SW1A 2AA. - In cell
B2, construct the clickable hyperlink:=HYPERLINK("https://www.google.com/maps/search/?api=1&query=" & ENCODEURL(A2), "View on Google Maps") - Clicking the resulting link opens the user’s browser directly to the exact pin location, regardless of spaces or special postal code formatting.
Example 3: Building REST API Endpoints with WEBSERVICE
Excel for Windows supports pulling raw web data directly into a cell using the WEBSERVICE function. When passing dynamic parameters into an API, always wrap user inputs in ENCODEURL:
=WEBSERVICE("https://api.agify.io?name=" & ENCODEURL(A2))
If cell A2 contains international characters or hyphenated names (such as Renée-Marie), ENCODEURL converts them into safe hexadecimal sequences (Ren%C3%A9e-Marie), ensuring the REST API processes the request successfully.
Character Transformation Reference Table
The following table illustrates how the ENCODEURL function converts common reserved characters in Excel:
| Original Character | Character Name | Encoded Output |
|---|---|---|
|
Space | %20 |
& |
Ampersand | %26 |
? |
Question Mark | %3F |
= |
Equals Sign | %3D |
/ |
Forward Slash | %2F |
# |
Hash / Pound | %23 |
+ |
Plus Sign | %2B |
@ |
At Symbol | %40 |
Important Rules and Best Practices
- Encode Parameters, Not the Base Domain: Never pass an entire URL including the protocol (such as
https://example.com/search) intoENCODEURL. Doing so will encode the colons and slashes (https%3A%2F%2F...), making the web browser unable to resolve the host. Only encode query parameter values. - Platform Availability:
ENCODEURLandWEBSERVICEare fully supported in Microsoft Excel for Windows (Excel 2013 and newer, including Microsoft 365). Note thatWEBSERVICEis unavailable in Excel for Mac due to operating system sandboxing restrictions, althoughENCODEURLfunctions normally across all platforms.