Atri R

New Member
Joined
Mar 26, 2018
Messages
11
Hello Folks,

I have a requirement to extract the domains from a list of URLs. I know this is quite trending and a petty common topic across generic internet search, however no formulas quite seem to match my specific query.

My file has a list of domains (which include subdomains and multiple TLDs). I only need to extract the parent domain and strip off any subdomain or TLD(s) from the list.

Example:

DomainExtracted
www.sub.domain.comdomain
https://sub.domain2.comdomain2
domain3.com.rudomain3
www.sub2.domain4.com.fldomain4
sub1.sub2.domain5.org.fldomain5

<tbody>
</tbody>

Note: there are multiple TLDs and multiple sub-domains. I know its quite troublesome, but would be great if someone can help.

Thanks
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Welcome to the MrExcel board!

Would this trap at least the majority of them?

Excel Workbook
AB
1DomainExtracted
2www.sub.domain.comdomain
3https://sub.domain2.comdomain2
4domain3.com.rudomain3
5www.sub2.domain4.com.fldomain4
6sub1.sub2.domain5.org.fldomain5
Sheet1
 
Upvote 0
ABCDEF
4www.sub.domain.comdomain =MID(B4,FIND("domain",B4),LEN("domain "))

<colgroup><col span="5"><col></colgroup><tbody>
</tbody>
 
Upvote 0
Welcome to the MrExcel board!

Would this trap at least the majority of them?

Sheet1

AB
1DomainExtracted
2www.sub.domain.comdomain
3https://sub.domain2.comdomain2
4domain3.com.rudomain3
5www.sub2.domain4.com.fldomain4
6sub1.sub2.domain5.org.fldomain5

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:188px;"><col style="width:88px;"></colgroup><tbody>
</tbody>

Spreadsheet Formulas
CellFormula
B2=TRIM(RIGHT(SUBSTITUTE(REPLACE(A2,MIN(SEARCH({".com.",".org.",".net.",".int.",".edu.",".gov.",".mil."},A2&".com.org.net.int.edu.gov.mil.")),99,""),".",REPT(" ",100)),100))

<tbody>
</tbody>

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4

Thanks Peter. This works perfectly. So if I come across any new TLDs which are not covered in the formula, can I just add them in the SEARCH tags?
 
Upvote 0
Thanks Peter. This works perfectly. So if I come across any new TLDs which are not covered in the formula, can I just add them in the SEARCH tags?
You would need to add each one twice. For example

=TRIM(RIGHT(SUBSTITUTE(REPLACE(A2,MIN(SEARCH({".com.",".org.",".net.",".int.",".edu.",".gov.",".mil.",".abc."},A2&".com.org.net.int.edu.gov.mil.abc.")),99,""),".",REPT(" ",100)),100))
 
Last edited:
Upvote 0
I figured that out. Thanks a ton!

One last query, I was checking my file and there seems to be a LOT of TLDs which are not standard. So I have to go through all 60k domains manually and add the ones which are not in the Formula.

Can you help me (if possible) with a VBA script which will hold a repository of all the domains and do the similar function that the formula is doing? Or if you can suggest any alternative way which will simplify the manual check?
 
Upvote 0
Would this user-define function be better? To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below and copy down.
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

Rich (BB code):
Function Domain(s As String) As String
  Dim Bits As Variant
  Dim i As Long
  
  'Add more TLDs below as required
  Const TLDs As String = ".com.org.net.int.edu.gov.mil." & _
                          "tld8.tld9.tld10.tld11.tld12.tld13.tld14.tld15.tld16.tld17." & _
                          "tld18.tld19.tld20.tld21.tld22.tld23.tld24."
                          
  Domain = "Not found"
  Bits = Split(s, ".")
  For i = UBound(Bits) To 1 Step -1
    If InStr(1, TLDs, "." & Bits(i) & ".", vbTextCompare) > 0 Then
      Domain = Bits(i - 1)
      Exit Function
    End If
  Next i
End Function

Excel Workbook
AB
1DomainExtracted
2www.sub.domain.comdomain
3https://sub.domain2.comdomain2
4domain3.com.rudomain3
5www.sub2.domain4.com.fldomain4
6sub1.sub2.domain5.org.fldomain5
7sub1.sub2.somedomain.tld2000.flNot found
8sub1.sub2.somedomain.tld20.flsomedomain
Sheet1
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,561
Messages
6,120,234
Members
448,951
Latest member
jennlynn

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top