Return domain name from URL

This tutorial shows how to return a domain name from a url through the use of an Excel formula or VBA

Example: Return domain name from URL

Return domain name from URL

METHOD 1. Return domain name from URL

EXCEL

=LEFT(B5,FIND("/",B5,9))
This formula uses a combination of the Excel LEFT and FIND functions to return only the domain name from a url.

METHOD 1. Return domain name from URL

VBA

Sub Return_Domain_Name_from_URL()
'declare variables
Dim ws As Worksheet
Dim DomName As String
Set ws = Worksheets("Analysis")
DomName = InStr(9, ws.Range("B5"), "/")
'return the domain name from a URL that is captured in cell B5
ws.Range("C5") = Left(ws.Range("B5"), DomName)

End Sub

ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("C5") in the VBA code.
URL: Select the cell that captures the URL from which you want get only the domain name by changing the cell reference ("B5") to a cell that captures the URL or changing the URL in cell ("B5") in the VBA code.
Worksheet Selection: Select the worksheet which captures the URL from which you want to extract the domain name by changing the Analysis worksheet name in the VBA code. You can also change the name of this object variable, by changing the name 'ws' in the VBA code.

Explanation about how to return domain name from URL

EXPLANATION

EXPLANATION

This tutorial shows how to extract a domain name from a url through the use of an Excel formula or VBA.
This tutorial provides one Excel method which uses the LEFT and FIND functions and one VBA methods which uses the Left and InStr functions to return only the domain name from a url.
FORMULA
=LEFT(url,FIND("/",url,9))
ARGUMENTS
url: The URL from which you want to get the domain name.

RELATED TOPICS

Related Topic Description Related Topic and Description
How to open a web page using VBA

RELATED FUNCTIONS

Related Functions Description Related Functions and Description
The Excel LEFT function returns the specified number of characters from a specified string, starting from the left side
The Excel FIND function returns the position of a specific sub-string within a string