Autofill email address via VBA

ashani

Active Member
Joined
Mar 14, 2020
Messages
347
Office Version
  1. 365
Platform
  1. Windows
Hi,

I wonder if someone could please guide me.

I'm looking for a VBA syntax to autofill email address. For example :

Cell A : Dan
Cell B : Smith

I would like in cell C to appear with Dan.Smith@test.com

The domain is the same name, just need to have first name dot last name and @test.com. However sometime there's space in the last name but I don't want any space in the email address.

Please can someone help me.

Many thanks
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Do you Specifically need VBA? This formula might be faster. In C1 (assuming A&B are on row 1) put this and drag down:
Excel Formula:
=CONCAT(TRIM(A1),".",TRIM(B1),"@test.com")
 
Upvote 0
The line in VBA would be:
VBA Code:
Cells(1,3) = Trim(Cells(1,1)) & "." & Trim(Cells(1,2)) & "@test.com"
But you'd have to put that in a sub and trigger it.
 
Upvote 0
sometime there's space in the last name but I don't want any space in the email address
Try
Excel Formula:
=SUBSTITUTE(A1&"."&B1&"@test.com"," ","")

Or with vba

VBA Code:
Sub FillEmail()
  With Range("C1:C" & Range("A" & Rows.Count).End(xlUp).Row)
    .Formula = "=SUBSTITUTE(A1&"".""&B1&""@test.com"","" "","""")"
    .Value = .Value
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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