I’ve written this code to create a list of email addresses from branch numbers. All the addresses are in the format:
lp0000@xxx.co.uk
The problem is some of the branch numbers are 3 digits so a zero is inserted in front of these e.g. 681 becomes 0681. I did this by using a custom number format 0000 but since the actual value of each is still 000 when the email addresses are created the starting zero is lost.
Can I write more code to copy the number format or do I need to write something to find all three digit numbers first and insert a 0 before them.
Option Explicit
Sub Pop_Emails()
Dim brno As String
Dim i As Integer
Dim wks As Worksheet
Set wks = Sheets("1A")
i = 2
Do While i <> 191
With wks
brno = .Cells(i, 1).Value
.Cells(i, 3) = "lp" & brno & "@xxxx.co.uk"
End With
i = i + 1
Debug.Print brno
Loop
End Sub
If
(i, 1)is"0001"with a custom format:will be
1, to get the formatted value simply: