Strip @ and domain name from email address

trovello

New Member
Joined
May 3, 2011
Messages
6
I need a macro to take an email address, strip off the "@" and full domain name. The length (and the domain name) will not be known. Example: jsmith@company.com to become just jsmith.

This will be used in other macros within my workbook and each entry could be different so a simple ctrl H on the column cannot be used.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Something like this?

Code:
Sub Email()
Dim r As Range

For Each r In Selection

    r.Value = Left(r.Value, WorksheetFunction.Find("@", r.Value) - 1)

Next r

End Sub
 
Upvote 0
Works great for a selection in worksheet - thanks for quick reply.

But how about coding an entire column "H" and stopping at the last entry?
 
Upvote 0
About to go to bed, but give this a whirl
Dim last_row as long
dim i as long
last_row = range("H" & rows.count).end(xlup).row

for i = 2 to end_row
with cells(i,8)
.value = Left(.Value, WorksheetFunction.Find("@", .Value) - 1)
end with
next i
 
Upvote 0
Perhaps this:

Code:
Sub StripEmail()
    Columns("H:H").Replace What:="@*", Replacement:=""
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,717
Members
452,939
Latest member
WCrawford

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