Parse out domain and top level domain from email address

domain

VBA code to extract domain and top level domain (.com, .net, etc.) from email address.

01.09.2022, Goran Dolenc
Categories: Excel VBA
Tags: domain email

How to?

Option Explicit

Sub Test()
Debug.Print getDomainOutOfEmail("goran.dolenc@siol.net")
Debug.Print getTopLevelDomainOutOfEmail("goran.dolenc@siol.net")
End Sub

Public Function getDomainOutOfEmail(inEmail As String) As String
'getDomainOutOfEmail = Mid(inEmail, InStrRev(inEmail, "@") + 1, InStrRev(inEmail, ".") - InStrRev(inEmail, "@") - 1) ' siol
getDomainOutOfEmail = Mid(inEmail, InStrRev(inEmail, "@") + 1, Len(inEmail)) ' siol.net
End Function

Public Function getTopLevelDomainOutOfEmail(inEmail As String) As String
getTopLevelDomainOutOfEmail = Mid(inEmail, InStrRev(inEmail, ".") + 1, Len(inEmail)) ' net
End Function