# Excel Formula to Get Domain Name from a URL

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

#### Question? Ask it in our Excel Forum ##### 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.)

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 