How to Get Domain Name From Url in Excel
Learn multiple Excel methods to get domain name from url with step-by-step examples and practical applications.
How to Get Domain Name From Url in Excel
Why This Task Matters in Excel
Extracting just the domain portion from a full web address may sound like a niche request, yet it appears in countless day-to-day data tasks. Imagine an online retailer downloading thousands of customer referral links and needing to know which partner websites are sending traffic. A marketing analyst might need to group newsletter clicks by destination domain. A cyber-security specialist could be auditing web logs for suspicious outbound calls. In each of these scenarios, the full universal resource locator (URL) stored in Excel—such as
https://subdomain.example.co.uk/path/page?utm_campaign=spring
—contains far more information than necessary. The analyst usually wants only example.co.uk. Being able to strip the protocol, any sub-domains, folders, parameters, and fragments lets the data professional quickly aggregate, count, or compare unique sites.
From an efficiency standpoint, Excel excels (pun intended) at transforming text at scale. Because URLs are simply text strings, Excel’s text functions, dynamic array functions such as TEXTAFTER, and even Power Query provide a flexible toolbox for domain extraction. Mastering those tools means you can automate what would otherwise be a tedious manual copy-paste or “find and delete” process.
Failing to know how to isolate the domain introduces real business risk. You might accidentally treat different sub-domains as separate websites, double-count visitors, or miss fraudulent links buried two folders deep. Worse, you could waste hours cleaning data by hand each reporting period, greatly slowing down decision-making.
Finally, the skill connects directly with broader Excel workflows. Domain extraction often sits at the top of larger pipelines that include deduplication with UNIQUE, summarization with PIVOT TABLES or SUMIFS, or cross-table lookups with XLOOKUP. Getting the domain fast and accurately means the rest of those tasks run smoother. Whether you work in marketing, IT, finance, research, or e-commerce, knowing how to pull the tidy domain out of messy web addresses is a fundamental spreadsheet super-power.
Best Excel Approach
The approach that gives the best mix of simplicity, speed, and compatibility is to combine the TEXTAFTER and TEXTBEFORE functions (Excel 365-only) or, for older versions, the classic LEFT and FIND pattern. TEXTAFTER removes everything before the double forward slash (//), and TEXTBEFORE chops everything after the next single slash, leaving only the host section of the URL. Here is the streamlined 365 formula that returns the bare domain even if the URL includes a trailing slash, query string, or fragment:
=TEXTBEFORE(TEXTAFTER(A2,"//"),"/")
Why this works
- TEXTAFTER(A2,\"//\") ^— removes the protocol (http, https, ftp, etc.) and returns everything that follows the slashes.
- TEXTBEFORE(…, \"/\") ^— trims everything from the first subsequent slash onward, giving us the host.
Use this method when:
- You have Microsoft 365 or Excel 2021 with TEXTAFTER/TEXTBEFORE.
- Performance matters and you want a single, easy-to-read formula.
- You maintain workbooks only in modern Excel versions.
Alternative for legacy Excel (2019 or earlier):
=LEFT(MID(A2,FIND("//",A2)+2,255),FIND("/",MID(A2,FIND("//",A2)+2,255)&"/")-1)
This classic approach uses MID to start after //, packs an artificial trailing slash to force FIND to succeed even when the URL has no path, and then returns the portion left of that slash. It is verbose but backward compatible.
Parameters and Inputs
When designing any domain-extraction formula, you must clarify three things:
- Source URL (required) – A text string in a single cell such as B2, or a dynamic array range like [B2:B1000]. It can be a fully qualified URL or a simple domain.
- Protocol patterns (implicit) – The recommended formulas assume the protocol ends with
://. They work for http, https, ftp, file, custom API schemes, etc. - Path delimiter
/(implicit) – The extraction stops at the first single slash after the protocol. If the URL has no further slash (e.g.,https://example.com), the formula still returns the full host because TEXTBEFORE handles the missing delimiter.
Data preparation guidelines:
- Ensure cells are formatted as General or Text so that Excel does not try to transform them into hyperlinks automatically.
- Remove leading or trailing spaces with TRIM or CLEAN if you imported data from another system.
- Validate that all URLs contain at least one
//; otherwise, wrap formulas in IFERROR or create a preprocessing step that prefixeshttp://for bare domains.
Edge cases:
- Internationalized domain names (IDNs) using punycode (
xn--…) still work because extraction treats them as plain text. - Embedded credentials (
https://user:pass@site.com) will returnuser:pass@site.comas part of the host in the simple formula; use additional splits on@if needed. - Ports (
https://example.com:8080) remain attached (example.com:8080) unless you trim at:.
Step-by-Step Examples
Example 1: Basic Scenario
Suppose cells [A2:A6] contain a list of mixed URLs:
| Row | URL |
|---|---|
| 2 | https://www.apple.com/iphone |
| 3 | http://microsoft.com/en-us/ |
| 4 | https://sub.domain.example.org |
| 5 | https://example.net/index.php?ref=adwords |
| 6 | https://shop.amazon.co.uk/gp/cart |
Goal: place a formula in B2, drag down, and get only the base host (not sub-folders).
Step-by-step
- Click cell B2.
- Enter the modern formula:
=TEXTBEFORE(TEXTAFTER(A2,"//"),"/")
- Press Enter. Excel immediately returns
www.apple.com. - Drag the fill handle down to B6. Results:
- B3 →
microsoft.com - B4 →
sub.domain.example.org - B5 →
example.net - B6 →
shop.amazon.co.uk
Why it works
TEXTAFTER strips everything before the protocol. Once the string starts at www.apple.com/iphone, TEXTBEFORE isolates the host before the next slash. For rows that have no path (row 4), TEXTBEFORE simply returns the whole string because no slash exists.
Common variations
- Remove
www.prefix by nesting SUBSTITUTE(TEXTBEFORE(...),\"www.\",\"\"). - Truncate sub-domains by reversing the string or splitting on dots—covered in Example 3.
Troubleshooting
If you see a #NAME? error, you are on an older Excel version. Switch to the legacy formula or convert the workbook to 365. If you see a hyperlink instead of text, change the Number Format to Text.
Example 2: Real-World Application
Scenario: A digital marketing agency receives daily export files containing thousands of referring URLs from social adverts. They need to aggregate clicks by unique domain to see which publishers outperform. The spreadsheet “March_Clicks.xlsx” contains a sheet named “Raw” with URLs in column D (starting at D2) and click counts in column E.
Goal: produce a summary sheet that lists each domain once and totals clicks.
Walkthrough
- In the same workbook, add a new sheet called “Summary.”
- On “Raw”, create a helper column F labeled “Domain”. In F2 enter:
=TEXTBEFORE(TEXTAFTER(D2,"//"),"/")
- Double-click the fill handle to populate down the entire dataset (Excel stops at the last record).
- Still on “Raw”, select [F1:E] (domain and clicks). Press Ctrl+T to convert into an official Excel Table named “tblClicks”.
- Go to the “Summary” sheet. In A2 enter a UNIQUE formula to list each distinct domain:
=UNIQUE(tblClicks[Domain])
- In B2 use SUMIFS to total clicks for each domain:
=SUMIFS(tblClicks[Clicks], tblClicks[Domain], A2#)
- Format as a Table or PivotChart if desired.
Business benefit
The agency now refreshes this workbook daily: they simply paste new raw data, Excel tables expand automatically, and the Summary tab recalculates. No manual parsing or VLOOKUP loops are required.
Performance considerations
With 50 000 rows, the TEXTAFTER + TEXTBEFORE combo remains fast because each row requires two straightforward text scans. Using dynamic arrays like UNIQUE keeps formulas minimal versus writing 50 000 SUMIFs manually.
Integration
This technique aligns with other features:
- You can create a PivotTable directly on “tblClicks” and drag “Domain” to the Rows area. The helper column remains the single source of truth.
- Use conditional formatting to highlight domains exceeding a click threshold.
Example 3: Advanced Technique
Problem: The security team needs only the base registrable domain (e.g., example.co.uk) from longer hosts like app1.dev.example.co.uk. The TEXTAFTER/TEXTBEFORE formula returns app1.dev.example.co.uk, which still includes sub-domains. They must strip everything except the last two segments because .co.uk is a known public suffix.
Advanced solution with LET and TEXTSPLIT (Excel 365):
=LET(
host, TEXTBEFORE(TEXTAFTER(A2,"//"),"/"),
parts, TEXTSPLIT(host,"."),
n, COUNTA(parts),
base, TEXTJOIN(".",-1, INDEX(parts, n-1):INDEX(parts, n)),
SWITCH(TRUE(),
base="co.uk", TEXTJOIN(".",-1, INDEX(parts, n-2):INDEX(parts, n)),
TRUE, base)
)
Explanation
hostvariable = domain with sub-domains.- TEXTSPLIT breaks it into an array of labels.
ncounts the labels.baseinitially concatenates the last two labels (typical for.comor.org).- If
baseequalsco.uk(indicating a multi-part public suffix), SWITCH pulls the last three labels instead. - The formula returns the registrable domain, easy for grouping by company rather than server.
Edge cases handled
- Works for
.com,.org,.net,.ioby default. - Specifically detects
.co.ukbut you can extend SWITCH to.gov.uk,.com.au, etc. - Because LET stores intermediate values, performance remains reasonable even for 100 000 rows.
Professional tips
- Wrap this logic into a named lambda function (Excel 365) called
GetBaseDomainso future users can call=GetBaseDomain(A2)like a built-in function. - For extremely large datasets, offload to Power Query where you can use regular expressions or native “Extract Domain” transform.
Tips and Best Practices
- Convert URL lists to Tables. Structured references (
tblData[URL]) reduce refactor headaches when rows grow. - Keep helper columns together. Place “Domain” immediately next to the original URL so downstream formulas remain aligned.
- Use LET to store intermediate values when formulas get long—this makes debugging easier and speeds up recalculation.
- Wrap extraction logic in IFERROR. A malformed URL should show blank or “Invalid” rather than break reports.
- Remove
www.only at the presentation layer. Retain the exact host for raw storage so you can still distinguish betweenwwwandshopif needed. - Document public-suffix edge cases. Maintain a small table listing
.co.uk,.com.au, and reference it in formulas or Power Query steps. Future editors will thank you.
Common Mistakes to Avoid
- Forgetting the trailing slash fallback – In older LEFT/FIND formulas, a URL with no path can return a
#VALUE!error. Always concatenate a slash inside FIND as shown in the legacy formula. - Stripping sub-domains indiscriminately – Removing everything before the second dot might break country domains like
something.co.uk. Build logic that accounts for multi-part suffixes. - Relying on manual copy-paste cleanup – It is slow and error-prone; one missed character can shift every subsequent column in your dataset. Automate with formulas or Power Query.
- Hard-coding column references – Using
A2when the URL might later move to column C causes brittle spreadsheets. Use Table structured references or named ranges. - Ignoring hyperlink formatting – Excel sometimes converts text into clickable links that visually hide whitespace. Force General format before importing or use RIGHT-click → Remove Hyperlinks.
Alternative Methods
Below is a concise comparison of widely used approaches:
| Method | Excel Version Support | Difficulty | Pros | Cons |
|---|---|---|---|---|
| TEXTAFTER + TEXTBEFORE | 365 / 2021 | Easy | Short formula, dynamic arrays | Not available in older versions |
| LEFT + FIND + MID (legacy) | All | Medium | Full backward compatibility | Long, harder to read |
| FILTERXML + SUBSTITUTE | 2013+ (Windows) | Medium | Uses XPath to parse URL | FILTERXML fails on some Macs, formula can be fragile |
| Power Query (Get & Transform) | 2010+ (with add-in) | Easy GUI | Handles millions of rows, regex possible | Requires refresh step, separate query layer |
| VBA custom function | All | Advanced | Ultimate flexibility, Regex | Macros may be disabled, maintenance overhead |
When to choose:
- Power Query for datasets beyond 100 000 rows or scheduled ETL pipelines.
- TEXTAFTER/TEXTBEFORE for quick ad-hoc analysis in modern Excel.
- Left-Find legacy formula for compatibility across mixed-version teams.
- VBA only when you need exotic parsing such as IDN punycode decoding and your organization allows macros.
Migration strategies
You can build workbooks with a helper sheet that checks IF(ISFUNCTION("TEXTAFTER"), … ) to choose formulas dynamically, allowing a single file to run on both old and new Excel versions.
FAQ
When should I use this approach?
Use formula-based extraction whenever you need an always-up-to-date domain value that recalculates as source URLs change, such as dashboards or PivotTables refreshed daily.
Can this work across multiple sheets?
Yes. Reference the URL cells with full sheet notation—e.g.,
=TEXTBEFORE(TEXTAFTER('January Data'!B2,"//"),"/")
You can also spill a dynamic array across sheets by naming it and referring to that name elsewhere.
What are the limitations?
TEXTAFTER/TEXTBEFORE are not available in Excel 2019 or earlier. Legacy formulas struggle with extremely long URLs (over 255 characters) because MID’s hard-coded length argument must cover the maximum possible string. Also, embedded credentials or ports require extra parsing.
How do I handle errors?
Wrap your core extraction inside IFERROR:
=IFERROR(TEXTBEFORE(TEXTAFTER(A2,"//"),"/"),"Invalid URL")
For broader integrity checks, use DATA → Data Validation to ensure every input contains //.
Does this work in older Excel versions?
The legacy LEFT/FIND method works all the way back to Excel 2007. FILTERXML also supports 2013 onwards on Windows, but not on Mac. For pre-2007, VBA or external preprocessing is necessary.
What about performance with large datasets?
Up to roughly 500 000 rows, formula methods remain fast on modern hardware. Beyond that, switch to Power Query which streams data more efficiently. Remember to disable automatic calculation during paste operations for very large models.
Conclusion
Being able to extract the domain name from any URL is a deceptively powerful Excel skill. It turns disorganized link dumps into structured, actionable information, unlocking faster aggregation, cleaner pivots, and reliable reporting. By mastering modern functions like TEXTAFTER and TEXTBEFORE—or their legacy equivalents—you ensure your workbooks stay compatible, performant, and easy to audit. As you grow in Excel proficiency, integrate this technique with Power Query, dynamic arrays, and custom LAMBDA functions to automate entire data pipelines. Practice the examples above on your own datasets, refine them for special suffixes, and soon you will handle even the messiest URL lists with confidence.
Related Articles
How to Show the 10 Most Common Text Values in Excel
Learn multiple Excel methods to list the 10 most frequent text values—complete with step-by-step examples, business use cases, and expert tips.
How to Abbreviate Names Or Words in Excel
Learn multiple Excel methods to abbreviate names or words with step-by-step examples and practical applications.
How to Abbreviate State Names in Excel
Learn multiple Excel methods to abbreviate state names with step-by-step examples, professional tips, and real-world applications.