Insert text before the @ character from email address in a cell

missch

New Member
Joined
Jun 23, 2015
Messages
3
Hi All

I know how to insert characters x spaces from left or right, but in my column have a list of email addresses.They are all completely different and vary in length an characters before and after the @ sign.

As an example I would like to change fred@smith.com to fred-123@smith.com and john@doe.com to john-123@doe.com.
The text to insert will always be -123 and always immediately before the @ sign.

Can anyone help please? I don't fancy doing 300 manually
Thanks :-)
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Can be done quickly using Power Query. Here is the Mcode

Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Split Column by Delimiter" = Table.SplitColumn(Source, "Column1", Splitter.SplitTextByDelimiter("@", QuoteStyle.Csv), {"Column1.1", "Column1.2"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Column1.1", type text}, {"Column1.2", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each [Column1.1]&"-123"),
    #"Reordered Columns" = Table.ReorderColumns(#"Added Custom",{"Column1.1", "Custom", "Column1.2"}),
    #"Merged Columns" = Table.CombineColumns(#"Reordered Columns",{"Custom", "Column1.2"},Combiner.CombineTextByDelimiter("@", QuoteStyle.None),"Merged"),
    #"Removed Columns" = Table.RemoveColumns(#"Merged Columns",{"Column1.1"})
in
    #"Removed Columns"
 
Last edited:
Upvote 0
You could replace @ with -123@ either by using crtl h.

Select the whole column first, then replace all.
 
Upvote 0
Brilliant, so simple, can’t believe I didn’t think of it! Thanks
 
Last edited:
Upvote 0
HI
If you like this code
Code:
Sub test()
    a = Application.Transpose(Cells(1, 1).Resize(Cells(Rows.Count, "a").End(xlUp).Row))
    With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = "\@"
        For i = 1 To UBound(a)
            a(i) = .Replace(a(i), "-123@")
        Next
    End With
    Cells(1, 2).Resize(UBound(a)) = a
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,815
Messages
6,181,136
Members
453,021
Latest member
Justyna P

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