Auto add text in changing field

S

Stephen

Is there a way to set upa cell or coloumn to add a email
addy text whenever I enter data? i.e. I put in username
and it auto adds @domain.com to the entry?
 
D

Dave Peterson

You could use an event macro:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Target, Range("a:a")) Is Nothing Then Exit Sub
If Target.Cells.Count > 1 Then Exit Sub
If Target.HasFormula Then Exit Sub

On Error GoTo errHandler:
With Target
If InStr(1, .Value, "@") > 0 Then
'already done
Else
Application.EnableEvents = False
.Value = Trim(.Value) & "@domain.com"
.Hyperlinks.Add anchor:=.Cells(1), _
Address:="mailto:" & .Value
End If
End With

errHandler:
Application.EnableEvents = True
End Sub

Right click on the worksheet tab and select view code. Paste this in.

I used range("a:a"), you can limit that to whatever you want.

If you're new to macros, David McRitchie has some notes at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top