Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Conseil Macro

1 réponse
Avatar
Calou
Bonjour,

Voilà quelques jours, Mishell m'avait constitué une macro qui me permettait
d'exploiter des fichier texte (environ 40 Mo environ)
http://cjoint.com/?dbePOloZak (ex dans le fichier)

Voici cette macro :
Private Sub CommandButton1_Click()
'Renseigner ici le chemin où se trouve le fichier
f = "E:\Philippe\CG63\Atelier\RAFP 2005\Copiedeessai.txt"
ligneAgent = UCase("AGENT:")
ligne = 1
'Renseigner ici le numéro de la rubrique de la recherche
ligneMontant = UCase("856")
suite = UCase("(suite)")
Open f For Input As 1
While Not EOF(1)
Line Input #1, a
a = Trim(a)
While Mid(a, 1, 1) = "!"
a = Mid(a, 2)
Wend
a = Trim(a)
If UCase(Mid(a, 1, Len(ligneMontant))) = ligneMontant Then
Line Input #1, k
k = Trim(k)
montant = ExtraireDernierMontant(k)
Cells(ligne, 2) = montant
End If
a = Trim(a)
If UCase(Mid(a, 1, Len(ligneMontant))) = ligneMontant Then
Line Input #1, k
k = Trim(k)
montant = ExtraireDernierMontant(k)
Cells(ligne, 3) = montant
End If
If UCase(Mid(a, 1, Len(ligneAgent))) = ligneAgent Then
nom = Trim(a)
If InStr(UCase(nom), suite) > 0 Then
b = InStr(UCase(nom), suite)
nom = Trim(Mid(nom, 1, b - 1))
End If
If UCase(nom) <> UCase(precedent) Then
ligne = ligne + 1
strnom = Trim(Mid(a, Len(ligneAgent) + 1))
famille = ""
prenom = ""
Call ExtraireNomDeFamilleEtPrenom(strnom, famille, prenom)
Cells(ligne, 1) = famille & " " & prenom
End If
precedent = nom
End If
Wend
Close
End Sub

Sub ExtraireNomDeFamilleEtPrenom(lignenom, ByRef famille, ByRef prenom)
a = lignenom
b = InStr(a, " ")
a = Trim(Mid(a, b + 1))
b = InStr(a, " ")
a = Trim(Mid(a, b + 1))
b = InStr(a, " ")
famille = Mid(a, 1, b - 1)
prenom = Trim(Mid(a, b + 1))
End Sub

Function ExtraireDernierMontant(a)
Dim t As Variant
t = Split(a, "!")
ExtraireDernierMontant = Trim(t(UBound(t) - 1))
End Function


Cette macro fonctionne à merveille. Cependant, maintenant, je voudrais
récupérer mois par mois avec le Nom Prénom en première colonne deuxième
colonne la base et en troisième le montant de la cotisation ensuite pour
février la meme chose et ainsi de suite.

Un grand merci par avance pour votre aide.

A +

1 réponse

Avatar
Mishell
Si j'ai bien compris.

http://cjoint.com/?drn2Hol06J

Mishell

"Calou" wrote in message
news:%
Bonjour,

Voilà quelques jours, Mishell m'avait constitué une macro qui me
permettait d'exploiter des fichier texte (environ 40 Mo environ)
http://cjoint.com/?dbePOloZak (ex dans le fichier)

Voici cette macro :
Private Sub CommandButton1_Click()
'Renseigner ici le chemin où se trouve le fichier
f = "E:PhilippeCG63AtelierRAFP 2005Copiedeessai.txt"
ligneAgent = UCase("AGENT:")
ligne = 1
'Renseigner ici le numéro de la rubrique de la recherche
ligneMontant = UCase("856")
suite = UCase("(suite)")
Open f For Input As 1
While Not EOF(1)
Line Input #1, a
a = Trim(a)
While Mid(a, 1, 1) = "!"
a = Mid(a, 2)
Wend
a = Trim(a)
If UCase(Mid(a, 1, Len(ligneMontant))) = ligneMontant Then
Line Input #1, k
k = Trim(k)
montant = ExtraireDernierMontant(k)
Cells(ligne, 2) = montant
End If
a = Trim(a)
If UCase(Mid(a, 1, Len(ligneMontant))) = ligneMontant Then
Line Input #1, k
k = Trim(k)
montant = ExtraireDernierMontant(k)
Cells(ligne, 3) = montant
End If
If UCase(Mid(a, 1, Len(ligneAgent))) = ligneAgent Then
nom = Trim(a)
If InStr(UCase(nom), suite) > 0 Then
b = InStr(UCase(nom), suite)
nom = Trim(Mid(nom, 1, b - 1))
End If
If UCase(nom) <> UCase(precedent) Then
ligne = ligne + 1
strnom = Trim(Mid(a, Len(ligneAgent) + 1))
famille = ""
prenom = ""
Call ExtraireNomDeFamilleEtPrenom(strnom, famille, prenom)
Cells(ligne, 1) = famille & " " & prenom
End If
precedent = nom
End If
Wend
Close
End Sub

Sub ExtraireNomDeFamilleEtPrenom(lignenom, ByRef famille, ByRef prenom)
a = lignenom
b = InStr(a, " ")
a = Trim(Mid(a, b + 1))
b = InStr(a, " ")
a = Trim(Mid(a, b + 1))
b = InStr(a, " ")
famille = Mid(a, 1, b - 1)
prenom = Trim(Mid(a, b + 1))
End Sub

Function ExtraireDernierMontant(a)
Dim t As Variant
t = Split(a, "!")
ExtraireDernierMontant = Trim(t(UBound(t) - 1))
End Function


Cette macro fonctionne à merveille. Cependant, maintenant, je voudrais
récupérer mois par mois avec le Nom Prénom en première colonne deuxième
colonne la base et en troisième le montant de la cotisation ensuite pour
février la meme chose et ainsi de suite.

Un grand merci par avance pour votre aide.

A +