Macro Basic Calc: problème de boucle
Résolu
Mycrobe
-
Mycrobe -
Mycrobe -
Bonjour,
Voilà; j'essaye de faire une fonction de tri avec des boucle, il recherche un valeur, et me copie toute la ligne dans ma seconde feuille.. et il ne me copie toujours que la 1ere ligne.... Même si j'enlève la recherche de le valeur 4 (valeur de ma 1ere ligne), ma boucle intermediaire qui me permet de copier la ligne du début à la fin marche, mais pas celle verticale de la recherche.
voila ma macro... si quelqu'un a une suggestion: (c est le nombre de lignes écrites et donc a tester)
Sub Exploitation
dim compteur as integer, CptCol as integer
dim z as integer, x as integer, b as integer, c as integer
c= Cellf("Feuille1",12,1).value
b=c+4
cptCol=5
compteur=4
For compteur= 4 To b
If Cellf("Feuille1",24,compteur).value=5 then
x=Cellf("feuille2",1,100).value +1
For cptCol=5 to 32
z= cptCol-3
Cellf("Feuille2",z,x).string=Cellf("Feuille1",CptCol,compteur).string
next
endif
Next
cptCol=5
compteur=4
For compteur=4 to b
If Cellf("Feuille1",24,compteur).value=4 then
x=Cellf("feuille2",1,100).value +1
For cptCol=5 to 32
z= cptCol-3
Cellf("Feuille2",z,x).string=Cellf("Feuille1",CptCol,compteur).string
next
endif
next
cptCol=5
compteur=4
For compteur= 4 to b
If Cellf("Feuille1",24,compteur).value=3 then
x=Cellf("feuille2",1,100).value +1
For cptCol=5 to 32
z= cptCol-3
Cellf("Feuille2",z,x).string=Cellf("Feuille1",CptCol,compteur).string
next
endif
next
cptCol=5
compteur=4
For compteur= 4 to b
If Cellf("Feuille1",24,compteur).value=2.5 then
x=Cellf("feuille2",1,100).value +1
For cptCol=5 to 32
z= cptCol-3
Cellf("Feuille2",z,x).string=Cellf("Feuille1",CptCol,compteur).string
next
endif
next
cptCol=5
compteur=4
For compteur= 4 to b
If Cellf("Feuille1",24,compteur).value=2 then
x=Cellf("feuille2",1,100).value +1
For cptCol=5 to 32
z= cptCol-3
Cellf("Feuille2",z,x).string=Cellf("Feuille1",CptCol,compteur).string
next
endif
next
cptCol=5
compteur=4
For compteur= 4 to b
If Cellf("Feuille1",24,compteur).value=1 then
x=Cellf("feuille2",1,100).value +1
For cptCol=5 to 32
z= cptCol-3
Cellf("Feuille2",z,x).string=Cellf("Feuille1",CptCol,compteur).string
next
endif
next
cptCol=5
compteur=4
For compteur= 4 to b
If Cellf("Feuille1",24,compteur).value=0 then
x=Cellf("feuille2",1,100).value +1
For cptCol=5 to 32
z= cptCol-3
Cellf("Feuille2",z,x).string=Cellf("Feuille1",CptCol,compteur).string
next
endif
next
End Sub
Voilà; j'essaye de faire une fonction de tri avec des boucle, il recherche un valeur, et me copie toute la ligne dans ma seconde feuille.. et il ne me copie toujours que la 1ere ligne.... Même si j'enlève la recherche de le valeur 4 (valeur de ma 1ere ligne), ma boucle intermediaire qui me permet de copier la ligne du début à la fin marche, mais pas celle verticale de la recherche.
voila ma macro... si quelqu'un a une suggestion: (c est le nombre de lignes écrites et donc a tester)
Sub Exploitation
dim compteur as integer, CptCol as integer
dim z as integer, x as integer, b as integer, c as integer
c= Cellf("Feuille1",12,1).value
b=c+4
cptCol=5
compteur=4
For compteur= 4 To b
If Cellf("Feuille1",24,compteur).value=5 then
x=Cellf("feuille2",1,100).value +1
For cptCol=5 to 32
z= cptCol-3
Cellf("Feuille2",z,x).string=Cellf("Feuille1",CptCol,compteur).string
next
endif
Next
cptCol=5
compteur=4
For compteur=4 to b
If Cellf("Feuille1",24,compteur).value=4 then
x=Cellf("feuille2",1,100).value +1
For cptCol=5 to 32
z= cptCol-3
Cellf("Feuille2",z,x).string=Cellf("Feuille1",CptCol,compteur).string
next
endif
next
cptCol=5
compteur=4
For compteur= 4 to b
If Cellf("Feuille1",24,compteur).value=3 then
x=Cellf("feuille2",1,100).value +1
For cptCol=5 to 32
z= cptCol-3
Cellf("Feuille2",z,x).string=Cellf("Feuille1",CptCol,compteur).string
next
endif
next
cptCol=5
compteur=4
For compteur= 4 to b
If Cellf("Feuille1",24,compteur).value=2.5 then
x=Cellf("feuille2",1,100).value +1
For cptCol=5 to 32
z= cptCol-3
Cellf("Feuille2",z,x).string=Cellf("Feuille1",CptCol,compteur).string
next
endif
next
cptCol=5
compteur=4
For compteur= 4 to b
If Cellf("Feuille1",24,compteur).value=2 then
x=Cellf("feuille2",1,100).value +1
For cptCol=5 to 32
z= cptCol-3
Cellf("Feuille2",z,x).string=Cellf("Feuille1",CptCol,compteur).string
next
endif
next
cptCol=5
compteur=4
For compteur= 4 to b
If Cellf("Feuille1",24,compteur).value=1 then
x=Cellf("feuille2",1,100).value +1
For cptCol=5 to 32
z= cptCol-3
Cellf("Feuille2",z,x).string=Cellf("Feuille1",CptCol,compteur).string
next
endif
next
cptCol=5
compteur=4
For compteur= 4 to b
If Cellf("Feuille1",24,compteur).value=0 then
x=Cellf("feuille2",1,100).value +1
For cptCol=5 to 32
z= cptCol-3
Cellf("Feuille2",z,x).string=Cellf("Feuille1",CptCol,compteur).string
next
endif
next
End Sub
A voir également:
- Macro Basic Calc: problème de boucle
- Telecharger macro convertir chiffre en lettre excel - Télécharger - Tableur
- Microsoft 365 basic - Accueil - Microsoft Office
- Visual basic - Télécharger - Langages
- Jitbit macro recorder - Télécharger - Confidentialité
- Visual basic editor - Télécharger - Langages
2 réponses
Bon, j'ai pas ton classeur mais d'après ce que je comprend de ta macro je pense que je suis pas loin.
Le tout en une seule boucle !
Tu dis
EDIT: CORECTION DU Critere
Sub Copie() Dim Depart As Worksheet Dim Arrivee As Worksheet Dim Lig As Long, FinLig As Long Dim LigDest As Long Dim Cherche As Variant Dim TB,e as byte, Critere Set Depart = Sheets("Feuil1") Set arrivée = Sheets("Feuil2") TB = Array(5, 4, 3, 2.5, 2, 1, 0) FinLig = Depart.Range("X65536").End(xlUp).Row 'Colonne 24 LigDest = 2 '1ère ligne où copier For e = 0 To 6 Critere =TB(e) For i = 4 To FinLig 'va jusque la fin du fichier 'Vérifie si la colonne 24 (X) = critere If Depart.Cells(Lig, 24) = Critere Then Depart.Range(Cells(Lig, 3), Cells(Lig, 29)).Copy Arrivee.Cells(LigDest, 5) LigDest = LigDest + 1 End If Next i Next e End Sub
Le tout en une seule boucle !
Tu dis
EDIT: CORECTION DU Critere
En tout cas, merci beaucoup de ton aide :-)