Separating Emails

zinah

Active Member
Joined
Nov 28, 2018
Messages
368
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have below that have "email / name". Is there any way that I can remove the names and the extra space below each email and keep only emails?

Email/NameExpected Results
a@abc.com / A b@abc.com / Ba@abc.com b@abc.com
a@abc.com / A f@abc.com / Fa@abc.com f@abc.com
d@abc.com / D e@abc.com / E f@abc.com / F
d@abc.com / D e@abc.com / E g@abc.com / G a@abc.com / A
 
If you did want to try a formula approach (not limited to 4 emails), you could try this based on your sample data.

zinah.xlsm
AB
1Email/NameResults
2a@abc.com / A b@abc.com / Ba@abc.com b@abc.com
3a@abc.com / A f@abc.com / Fa@abc.com f@abc.com
4d@abc.com / D e@abc.com / E f@abc.com / F d@abc.com e@abc.com f@abc.com
5d@abc.com / D e@abc.com / E g@abc.com / G a@abc.com / A d@abc.com e@abc.com g@abc.com a@abc.com
Sheet4
Cell Formulas
RangeFormula
B2:B5B2=TEXTJOIN(CHAR(10),1,TRIM(LEFT(SUBSTITUTE(FILTERXML("<p><c>"&SUBSTITUTE(A2,CHAR(10)&CHAR(10),"</c><c>")&"</c></p>","//c")," ",REPT(" ",100)),100)))
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try this version. It is just the 'Pattern' line that has changed.

Rich (BB code):
Sub ExtractEmails()
  Dim RX As Object
  Dim a As Variant, b As Variant
  Dim i As Long
 
  Set RX = CreateObject("VBScript.RegExp")
  RX.Global = True
  RX.Pattern = " [^@]+( |" & vbLf & "|$)"
  a = Range("A2", Range("A" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To UBound(a), 1 To 1)
  For i = 1 To UBound(a)
    b(i, 1) = Replace(RTrim(RX.Replace(a(i, 1), " ")), " ", vbLf)
  Next i
  Range("B2").Resize(UBound(b)).Value = b
End Sub
Thank you so much, the macro worked perfectly great. I really appreciate your kind help!
 
Upvote 0
If you did want to try a formula approach (not limited to 4 emails), you could try this based on your sample data.

zinah.xlsm
AB
1Email/NameResults
2a@abc.com / A b@abc.com / Ba@abc.com b@abc.com
3a@abc.com / A f@abc.com / Fa@abc.com f@abc.com
4d@abc.com / D e@abc.com / E f@abc.com / F d@abc.com e@abc.com f@abc.com
5d@abc.com / D e@abc.com / E g@abc.com / G a@abc.com / A d@abc.com e@abc.com g@abc.com a@abc.com
Sheet4
Cell Formulas
RangeFormula
B2:B5B2=TEXTJOIN(CHAR(10),1,TRIM(LEFT(SUBSTITUTE(FILTERXML("<p><c>"&SUBSTITUTE(A2,CHAR(10)&CHAR(10),"</c><c>")&"</c></p>","//c")," ",REPT(" ",100)),100)))
That's really kind of you! I loved the formula and it worked too :)
 
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

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