1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
Sub telNb()
Dim reg
Dim obj
Dim txt()
Dim i As Long, j As Long, Ligne As Long, Colonne As Long
Dim Cel As Range, C, tabColonne, Cols, arrSelection, P As Range
On Error Resume Next
Set P = Application.InputBox("Sélectionnez les colonnes à normaliser :", Type:=8)
On Error GoTo 0
Application.DisplayAlerts = True
If P Is Nothing Then
MsgBox "Sélection annulée"
Exit Sub
End If
txt = Array("01.35.08.99.52", _
"0135089952", _
"01-35-08-99-52", _
"01 35 08 99 52", _
"+331.35.08.99.52", _
"+33(0)1-35-08-99-52", _
"+33135089952", _
"331 35 08 99 52", _
"01/35/08/99/52", _
"01\35\08\99\52", _
"01,35,08,99,52", _
"331" & VBA.Chr(9) & "35" & VBA.Chr(9) & "08" & VBA.Chr(9) & "99" & VBA.Chr(9) & "52", _
"331" & VBA.Chr(10) & "35" & VBA.Chr(10) & "08" & VBA.Chr(10) & "99" & VBA.Chr(10) & "52", _
"331" & VBA.Chr(160) & "35" & VBA.Chr(160) & "08" & VBA.Chr(160) & "99" & VBA.Chr(160) & "52")
Set reg = CreateObject("VBScript.RegExp")
reg.Global = True
arrSelection = P.Address(False, False)
tabColonne = Split(arrSelection, ",")
For i = 0 To UBound(tabColonne)
C = GetColumnRange(tabColonne(i))
Cols = Split(C, ";")
For j = 0 To UBound(Cols)
Colonne = CLng(Cols(j))
Ligne = Cells(Rows.Count, Colonne).End(xlUp).Row
For Each Cel In Range(Cells(2, Colonne), Cells(Ligne, Colonne))
reg.Pattern = "(\D)" 'tout ce qui n'est pas numerique
If Cel.Value <> "" Then
Cel.Value = "0" & Format(Right(reg.Replace(Cel, ""), 9), "# ## ## ## ##")
End If
Next Cel
Next
Next
MsgBox "Traitement Terminé"
End Sub |