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
Extract Sub-Domain + Domain 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.
=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.
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.
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.
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.