I am trying to write a VBA Script to format a list of several thousdand phone numbers I have stored in an excel spread sheet. So far I have this, but when I run it it doesn’t format the phone number. It does add the value NULL if the cell is empty but doesnt format the number anyone see what I am doing wrong?
Sub CheckPhoneNumber()
Dim retNumber As String
Range("K3").Activate
Do Until ActiveCell.Row = 3746
If ActiveCell.Value = "" Then
ActiveCell.Value = "NULL"
Else
For i = 1 To Len(ActiveCell.Value)
If Asc(Mid(ActiveCell.Value, i, 1)) >= Asc("0") And Asc(Mid(ActiveCell.Value, i, 1)) <= Asc("9") Then
retNumber = retNumber + Mid(ActiveCell.Value, i, 1)
End If
Next
If Len(retNumber) > 10 Then
cleanPhoneNumber = Format(retNumber, "(+#) 000-000-0000")
Else
cleanPhoneNumber = Format(retNumber, "000-000-0000")
End If
End If
ActiveCell.Offset(1, 0).Activate
Loop
End Sub
Looks like you forgot to write
cleanPhoneNumberback to the sheet? you need anActiveCell.Value = cleanPhoneNumberbefore the finalend if.