Excel Formula to Get Domain Name from a URL

Add to Favorites
Author: | Edits: don

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

bf985c22358847c85b1a333814cdd7a2.png

Sections:

Extract Domain Name from URL

Extract Sub-Domain + Domain from URL

Potential Issues

Notes

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))), " ", ".")

cdd20c4c4d79b8ee2e8d0ba85fd267c8.png

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.", "")

c2638ef0169de0940c5ffc40603c4fd1.png

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.

9c900392b816e31e2062dcad9d4e0e0d.png

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.


Downloadable Files: Excel File

Question? Ask it in our Excel Forum


Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons 50+ Hours of Instruction 200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Similar Content on TeachExcel
Get the Name of a Worksheet in Macros VBA in Excel
Tutorial: How to get the name of a worksheet in Excel using VBA and Macros and also how to store tha...
Get the Day of Week from a Date in Excel
Tutorial: How to get the name of a day from a date in Excel. This returns, for example, "Tuesday" fo...
Formula to Get the Last Value from a List in Excel
Tutorial: Formulas that you can use to get the value of the last non-empty cell in a range in Excel...
Excel Formulas Won't Update
Tutorial: How to get your Excel formulas to update when you edit a worksheet. By default, each time...
Remove All Filtering From a Worksheet in Excel
Macro: This Excel macro removes all filtering from a worksheet in Excel. This allows you to compl...
Input Form to Get Data and Store it in Another Tab in Excel
Tutorial: How to make a user input form in Excel and have the data stored on another worksheet at th...
Tutorial Details
Downloadable Files: Excel File
Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course