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
Sub Return_Domain_Name_from_URL()
'declare variables
Dim ws As Worksheet
Dim DomName As String
Dim ws As Worksheet
Dim DomName As String
Set ws = Worksheets("Analysis")
DomName = InStr(9, ws.Range("B5"), "/")
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)
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.
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
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))
=LEFT(url,FIND("/",url,9))
ARGUMENTS
url: The URL from which you want to get the domain name.
url: The URL from which you want to get the domain name.
RELATED TOPICS
Related Topic | Description | Related Topic and Description |
---|---|---|
Open a web page | How to open a web page using VBA |
RELATED FUNCTIONS
Related Functions | Description | Related Functions and Description |
---|---|---|
LEFT Function | The Excel LEFT function returns the specified number of characters from a specified string, starting from the left side | |
FIND Function | The Excel FIND function returns the position of a specific sub-string within a string |