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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,221,418
Messages
6,159,791
Members
451,589
Latest member
Harold14

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