Subscribe for Weekly Tutorials
BONUS: subscribe now to download our Top Tutorials Ebook!
Excel Formula to Get Domain Name from a URL
Two formulas that you can use to extract the domain name from a URL or to extract the sub-domain along with the domain name.
Note: These formulas work with .com as well as international domains, such as .co.uk
Sections:
Extract Sub-Domain + Domain from URL
Extract Domain Name from URL
=SUBSTITUTE(TRIM(RIGHT(SUBSTITUTE(REPLACE(REPLACE(A2, 1, IFERROR(FIND("//", A2)+1, 0), "")&"/", FIND("/", REPLACE(A2, 1, IFERROR(FIND("//", A2)+1, 0), "")&"/"), LEN(A2), ""), ".", REPT(" ", LEN(A2))), IF(LEN(A2)-LEN(SUBSTITUTE(A2,".",""))=2,LEN(A2)*2,LEN(A2)*3))), " ", ".")
This formula is Plug & Play so you can copy/paste it into your spreadsheet and the only thing you need to do is change the cell references to point to the cell with the URL.
A2 is the current cell reference, to change it quickly, copy the above formula into a blank worksheet and then hit Ctrl + F and go to the Replace tab and input A2 in the "Find what" input and the desired cell reference into the "Replace with" input.
Extract Sub-Domain + Domain from URL
=SUBSTITUTE(REPLACE(REPLACE(A2, 1, IFERROR(FIND("//", A2)+1, 0), "")&"/", FIND("/", REPLACE(A2, 1, IFERROR(FIND("//", A2)+1, 0), "")&"/"), LEN(A2), ""), "www.", "")
This formula is Plug & Play so you can copy/paste it into your spreadsheet and the only thing you need to do is change the cell references to point to the cell with the URL.
A2 is the current cell reference, to change it quickly, copy the above formula into a blank worksheet and then hit Ctrl + F and go to the Replace tab and input A2 in the "Find what" input and the desired cell reference into the "Replace with" input.
Potential Issues
These are the most versatile Excel formulas on the web that extract a domain name from a URL. (If you disagree, please contact us!)
However, there are some instances when these formulas will have issues.
Issue
When you have a domain that has multiple endings, such as .co.uk that domain must have a www. in front of it in order for the formula that returns just the domain name to work.
Here is a screenshot of the sample file, with the Domain formula in column B and the Sub-Domain+Domain formula in column C.
At the moment, this is the only known limitation of the above formulas.
Notes
The above formulas are rather complex; I recommend simply copy/pasting them and saving them for future use.
Make sure to download the sample file so you can see these formulas in Excel and also see a long list of sample URLs that show you how versatile these formulas are.
Question? Ask it in our Excel Forum
Tutorial: How to get the name of a worksheet in Excel using VBA and Macros and also how to store tha...
Tutorial: How to get the name of a day from a date in Excel. This returns, for example, "Tuesday" fo...
Tutorial: Formulas that you can use to get the value of the last non-empty cell in a range in Excel...
Tutorial: How to get your Excel formulas to update when you edit a worksheet. By default, each time...
Macro: This Excel macro removes all filtering from a worksheet in Excel. This allows you to compl...
Tutorial: How to make a user input form in Excel and have the data stored on another worksheet at th...