Séparer l'adresse, le code postal et la ville ?

abouam

XLDnaute Nouveau
Bonjour et BONNE et HEUREUSE ANNÉE à vous tous !

je possède un tabelau qui contient des lignes comme suit :

rue de Siam 07100 Brest

Je souhaite avoir 3 colonnes qui auront comme titre :
Adresse
Code postale
Ville

Donc une extraction de données.
Voici mon fichier exemple
Merci
 

Pièces jointes

  • ADRESSES.xls
    18 KB · Affichages: 1 325
  • ADRESSES.xls
    18 KB · Affichages: 1 426
  • ADRESSES.xls
    18 KB · Affichages: 1 455

ROGER2327

XLDnaute Barbatruc
Re : Séparer l'adresse, le code postal et la ville ?

Re…
Bonjour à tous, bonjour Roger2327

Pour notre culture, pourquoi ce "décervelage" en bas de ton post ?

Merci

@ plus
Tibo a répondu ce qu'il faut. Esprit fin et perspicace, il a saisi qu'il s'agit d'un affaire très-sérieuse, et je l'en félicite.​
Bonne soirée.

ROGER2327
#4874


Mardi 17 Décervelage 138 (Saint Mandrin, poète et philosophe, SQ)
25 Nivôse An CCXIX
2011-W02-5T15:41:06Z
 

JNP

XLDnaute Barbatruc
Re : Séparer l'adresse, le code postal et la ville ?

Bonsoir le fil :),
Avec beaucoup de retard et seulement pour le fun (étonné que david84 n'ai pas essayé ;)...).
Une possibilité RegExp
VB:
Dim Match, Matches
Function ExtractionCP(Cellule As Range) As String
Application.Volatile
With CreateObject("vbscript.regexp")
.Global = True
.Pattern = " \d{5} "
Set Matches = .Execute(Cellule.Text)
If Matches.Count >= 1 Then ExtractionCP = Trim(Matches(0))
End With
End Function
Function ExtractionRue(Cellule As Range) As String
Application.Volatile
With CreateObject("vbscript.regexp")
.Global = True
.Pattern = "^.* \d{5} "
Set Matches = .Execute(Cellule.Text)
If Matches.Count >= 1 Then ExtractionRue = Left(Matches(0), Len(Matches(0)) - 7)
End With
End Function
Function ExtractionVille(Cellule As Range) As String
Application.Volatile
With CreateObject("vbscript.regexp")
.Global = True
.Pattern = " \d{5} .*$"
Set Matches = .Execute(Cellule.Text)
If Matches.Count >= 1 Then ExtractionVille = Right(Matches(0), Len(Matches(0)) - 7)
End With
End Function
Voir PJ ;).
Bonne soirée :cool:
 

Pièces jointes

  • ADRESSES(1).xls
    38.5 KB · Affichages: 226
  • ADRESSES(1).xls
    38.5 KB · Affichages: 201
  • ADRESSES(1).xls
    38.5 KB · Affichages: 242
Dernière édition:

JNP

XLDnaute Barbatruc
Re : Séparer l'adresse, le code postal et la ville ?

Bonjour le fil :),
Encore pour le fun, je me suis dit : et si y en a un qui habite "Rue des 50000 Totos 13000 Marseille" :p...
J'ai donc réétudié mes RegExp et vous propose une version qui le supporte correctement :
VB:
Dim Match, Matches
Function ExtractionCP(Cellule As Range) As String
Application.Volatile
With CreateObject("vbscript.regexp")
.Global = True
.Pattern = " \d{5} "
Set Matches = .Execute(Cellule.Text)
If Matches.Count >= 1 Then ExtractionCP = Trim(Matches(Matches.Count - 1))
End With
End Function
Function ExtractionRue(Cellule As Range) As String
Application.Volatile
With CreateObject("vbscript.regexp")
.Global = True
.Pattern = "^.* \d{5} "
Set Matches = .Execute(Cellule.Text)
If Matches.Count >= 1 Then ExtractionRue = Left(Matches(0), Len(Matches(0)) - 7)
End With
End Function
Function ExtractionVille(Cellule As Range) As String
Application.Volatile
With CreateObject("vbscript.regexp")
.Global = True
.Pattern = " \d{5} [^0-9]*$"
Set Matches = .Execute(Cellule.Text)
If Matches.Count >= 1 Then ExtractionVille = Right(Matches(0), Len(Matches(0)) - 7)
End With
End Function
Bonne journée :cool:
 

Discussions similaires

Statistiques des forums

Discussions
312 305
Messages
2 087 077
Membres
103 455
dernier inscrit
saramachado