Macro extraire texte en Majuscule

Fermé
Applemilk Messages postés 8 Date d'inscription mercredi 4 août 2010 Statut Membre Dernière intervention 1 août 2011 - 4 août 2010 à 15:14
lermite222 Messages postés 8702 Date d'inscription dimanche 8 avril 2007 Statut Contributeur Dernière intervention 22 janvier 2020 - 4 août 2010 à 18:19
Bonjour,

J'ai besoin de récuperer des infos dans un tableau pour les mettre dans un autre. Une macro est déjà en place mais il faudrait que je la modifie, je voudrais prendre uniquement ce qui apparait en majuscule dans une case avant et après des tirets.

La case est sous cette forme:
PORTAGE-TLILI mustapha - SITE INSPECTOR


Je voudrais juste le TLILI
Les caractères en maj après le premier tiret et avant le deuxième...

La macro déjà en place est la suivante:


If Left(xls.Worksheets("ANNEXE TRVX ST").Cells(kj, 4), 3) = "POR" Then
début = InStr(1, xls.Worksheets("ANNEXE TRVX ST").Cells(kj, 4), "-")
long1 = Len(xls.Worksheets("ANNEXE TRVX ST").Cells(kj, 4))
nom = Right(xls.Worksheets("ANNEXE TRVX ST").Cells(kj, 4), (long1 - début))
fin = InStr(1, nom, "-")
long2 = Len(nom)
If fin > 0 Then
nom2 = Left(nom, fin - 1)
Else
nom2 = nom
End If

fin2 = InStr(nom2, " ")
If fin2 > 0 Then
nom3 = Left(nom2, fin2 - 1)
Else
nom3 = nom2
End If

Else
fin = InStr(1, xls.Worksheets("ANNEXE TRVX ST").Cells(kj, 4), "-")
long2 = Len(xls.Worksheets("ANNEXE TRVX ST").Cells(kj, 4))
If fin > 0 Then
nom2 = Left(xls.Worksheets("ANNEXE TRVX ST").Cells(kj, 4), fin - 1)
Else
nom2 = xls.Worksheets("ANNEXE TRVX ST").Cells(kj, 4)
End If

fin2 = InStr(nom2, " ")
If fin2 > 0 Then
nom3 = Left(nom2, fin2 - 1)
Else
nom3 = nom2
End If

End If


Merci beacuoup d'avance!!

A voir également:

1 réponse

lermite222 Messages postés 8702 Date d'inscription dimanche 8 avril 2007 Statut Contributeur Dernière intervention 22 janvier 2020 1 190
4 août 2010 à 18:19
Bonjour,
Peut-être avec ...
Public Function Extrait(Var As String) As String
Dim TB, i As Integer
    TB = Split(Var, "-")
    For i = 1 To Len(TB(1))
        If Asc(Mid(TB(1), i, 1)) > 90 Or Asc(Mid(TB(1), i, 1)) < 65 Then Exit For
    Next
    Extrait = Left(TB(1), i - 1)
End Function

A+
0