vbanewbie68
Board Regular
- Joined
- Oct 16, 2021
- Messages
- 171
- Office Version
- 365
- Platform
- Windows
- MacOS
Hello
I have a CSV file. One of the headers is Mobile Number. The first digit '0' is missing because of CSV Format. See below. I am trying to split it into this example 07445 25211.
Mobile number
7744525211
7744568256
7755775775
7822258548
The code below.
Thank you
Regards
V
I have a CSV file. One of the headers is Mobile Number. The first digit '0' is missing because of CSV Format. See below. I am trying to split it into this example 07445 25211.
Mobile number
7744525211
7744568256
7755775775
7822258548
The code below.
VBA Code:
Sub tidyMobile(LastR)
MobC = Application.Match("Mobile", msheet.Cells(1, 1).EntireRow, 0) 'Mobile Col
mobArray = Split(" 7|07|447|+447|+07|44 7|+44 7|(44)7|(+44)7|(44) 7|(+44) 7", "|") 'Array of typical UK mobile starts
For x = 2 To LastR
MPhone = msheet.Cells(x, MobC).Value 'Mobile Number Provided
'Tidy phone
For I = 1 To 9
If Left(MPhone, Len(mobArray(I))) = mobArray(I) Then
MPhone = "07" & Mid(MPhone, Len(mobArray(I)) + 1)
Exit For
End If
Next I
If InStr(1, MPhone, " ", vbTextCompare) = 0 And Left(MPhone, 2) = "07" Then
'Else if value in mobile, ensure space exists for those starting with 0
MPhone = Left(MPhone, 5) & " " & Mid(MPhone, 6)
End If
msheet.Cells(x, MobC).Value = MPhone
Next x
End Sub
Thank you
Regards
V
Last edited by a moderator: