Create array of e-mail address from array of names

horizonflame

Board Regular
Joined
Sep 27, 2018
Messages
184
Office Version
  1. 2013
Hi everyone

I have a list of names such as "John Smith" in A1:A20. I need to get these names into an array of people's e-mail addresses . The format output in the array would be "John.Smith@company.com".

Many thanks for your help guys.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
CAn you post a small sample of the data and what you expect as a result ?
 
Upvote 0
Where are the @company names stored ??
IS this what you are trrying to
VBA Code:
Sub MM1()
Dim r As Long
For r = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
    Cells(r, 1) = Cells(r, 1) & "@company.com"
Next r
End Sub
 
Upvote 0
Hi @MichaelM

The string "@company.com" is the same for all recipients. There is a decimal point between the first and second name which I couldn't see in your code.

I would like to create an array of the e-mail addresses as I will pass this array to my code to send the emails.

Thanks again
 
Upvote 0
VBA Code:
Sub MM1()
Dim myArray As Variant, r As Long
For r = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
    Cells(r, 1) = Replace(Cells(r, 1), " ", ".")
    Cells(r, 1) = Cells(r, 1) & "@company.com"
Next r
myArray = [A2:A20]
End Sub
 
Upvote 0
Something like this?
(I have assumed no blank cells in the column A range)

VBA Code:
Sub Email_Addr_Array()
  Dim OutAry As Variant
  Const dom As String = "@company.com"
  OutAry = Split(Replace(Join(Application.Transpose(Range("A1", Range("A" & Rows.Count).End(xlUp)).Value), dom & "|") & dom, " ", "."), "|")
End Sub

BTW, I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
Solution
You're welcome. Glad we could help. :)

.. and thanks for updating your profile. (y)
 
Upvote 0
Hello HorizonFlame

When I ran Michael's code (post #6) I found that it did not change the person's name that was stored in cell A1. Also, it destroyed the original names, which may or may not be okay.

In view of this, I'd like to offer a slightly modified version. This code loads all the names into an array first, which should speed up the processing slightly.
VBA Code:
Sub ReformatNames()
    Dim TotalRows As Long
    Dim RowNum As Long
    Dim Ary As Variant

    RowNum = 1
    TotalRows = Rows(Rows.Count).End(xlUp).Row
    Ary = Range(Cells(1, 1), Cells(TotalRows, 1)).Value

For RowNum = 1 To TotalRows
    Ary(RowNum, 1) = Replace(Cells(RowNum, 1), " ", ".")
    Ary(RowNum, 1) = Ary(RowNum, 1) & "@company.com"
Next RowNum
End Sub

TotallyConfused
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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