Macro en boucle qui ne fonctionne pas
Steugeu
-
melanie1324 Messages postés 1504 Date d'inscription Statut Membre Dernière intervention -
melanie1324 Messages postés 1504 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Je suis sur un tableau Excel, et je souhaiterai créer une marco en boucle pour que celle ci me fasse des calculs à partir de certaines cellules.
En gros, j'ai des chiffres dans ma colonne A sur les lignes 3 à15.
J'ai mis une condition pour démarrer qui est : si A3 est > 1 alors il me fait des calculs sur les colonnes B3, C3, D3 etc etc.... et en fait je n'arrive pas a faire la boucle pour que cette formule se reproduise sur les lignes en dessous.
QQ'un pourrait-il m'aider ?
Merci beaucoup !!
Je suis sur un tableau Excel, et je souhaiterai créer une marco en boucle pour que celle ci me fasse des calculs à partir de certaines cellules.
En gros, j'ai des chiffres dans ma colonne A sur les lignes 3 à15.
J'ai mis une condition pour démarrer qui est : si A3 est > 1 alors il me fait des calculs sur les colonnes B3, C3, D3 etc etc.... et en fait je n'arrive pas a faire la boucle pour que cette formule se reproduise sur les lignes en dessous.
QQ'un pourrait-il m'aider ?
Merci beaucoup !!
A voir également:
- Macro en boucle qui ne fonctionne pas
- Telecharger macro convertir chiffre en lettre excel - Télécharger - Tableur
- Télécharger macro convertir chiffre en lettre excel - Télécharger - Tableur
- Jitbit macro recorder - Télécharger - Confidentialité
- Excel récupérer couleur cellule sans macro ✓ - Forum Bureautique
- Tv orange chargement en boucle ✓ - Forum TV & Vidéo
13 réponses
oui une seule cellule qui s'appelle totale.
Au lieu de Do While i< range("total").row
écrit :
Do While i<= range("total").row
Au lieu de Do While i< range("total").row
écrit :
Do While i<= range("total").row
Bonjour,
Pour faire une boucle sur des lignes
for i =3 to 15
'tu mets ce que ca fait sur ta colonne
next i
Pour faire une boucle sur des lignes
for i =3 to 15
'tu mets ce que ca fait sur ta colonne
next i
Bonjour,
Pour faire une boucle sur des lignes
for i =3 to 15
'tu mets ce que ca fait sur ta colonne
'i est ta variable de ligne donc tes cellules doivent être cells(i,1) pour taligne 1ère colonne
'cells(i,2) pour ta ligne et 2e colonne...
next i
Si tu as du mal mets ton code en entier et je t'aiderais
Pour faire une boucle sur des lignes
for i =3 to 15
'tu mets ce que ca fait sur ta colonne
'i est ta variable de ligne donc tes cellules doivent être cells(i,1) pour taligne 1ère colonne
'cells(i,2) pour ta ligne et 2e colonne...
next i
Si tu as du mal mets ton code en entier et je t'aiderais
Bonjour Mélanie, déjà merci pour ta réponse :)
Voici donc mon chef d'oeuvre :)
'
Do
ActiveCell.Offset(12, B).Select
If ActiveCell.Value > 1 Then
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C/TOTAL"
Range("D12").Select
ActiveCell.FormulaR1C1 = "=ROUND(RC[-2]*R[-1]C/TOTAL,2)"
Range("E12").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-1]C/TOTAL"
Range("F12").Select
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-1]"
Range("G12").Select
ActiveCell.FormulaR1C1 = "=RC[-3]"
Range("C13").Select
End If
Loop Until ActiveCell.Value = 0
End Sub
Mon soucis c'est qu'en fait le nombre de ligne peut varier ! là tu vois j'ai mis de la ligne 3 a 15 mais ça peut etre + ou - que ça !!
Ca doit pas etre compliqué je pense !! C'est juste de la logique !!
A partir de la cellule C12, je fais des calculs sur les cellules D12, E12 F12 et G12.
Après cela je veux que ma macro (incluant tous mes cacluls) se répète sur les lignes en dessous (donc à partir de C13 poure les cellules D13 E13 etc etc) !!!
Voici donc mon chef d'oeuvre :)
'
Do
ActiveCell.Offset(12, B).Select
If ActiveCell.Value > 1 Then
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C/TOTAL"
Range("D12").Select
ActiveCell.FormulaR1C1 = "=ROUND(RC[-2]*R[-1]C/TOTAL,2)"
Range("E12").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-1]C/TOTAL"
Range("F12").Select
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-1]"
Range("G12").Select
ActiveCell.FormulaR1C1 = "=RC[-3]"
Range("C13").Select
End If
Loop Until ActiveCell.Value = 0
End Sub
Mon soucis c'est qu'en fait le nombre de ligne peut varier ! là tu vois j'ai mis de la ligne 3 a 15 mais ça peut etre + ou - que ça !!
Ca doit pas etre compliqué je pense !! C'est juste de la logique !!
A partir de la cellule C12, je fais des calculs sur les cellules D12, E12 F12 et G12.
Après cela je veux que ma macro (incluant tous mes cacluls) se répète sur les lignes en dessous (donc à partir de C13 poure les cellules D13 E13 etc etc) !!!
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Bonjour,
il faut revoir tout ton code :
for i =3 to 15
cells(i,1).select
Do cells(i,1)=0
If ActiveCell.Value > 1 Then
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C/TOTAL"
cells(i,4).select
ActiveCell.FormulaR1C1 = "=ROUND(RC[-2]*R[-1]C/TOTAL,2)"
cells(i,5).select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-1]C/TOTAL"
cells(i,6).select
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-1]"
cells(i,7).selecr
ActiveCell.FormulaR1C1 = "=RC[-3]"
End If
Loop
next i
Ca marche?
il faut revoir tout ton code :
for i =3 to 15
cells(i,1).select
Do cells(i,1)=0
If ActiveCell.Value > 1 Then
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C/TOTAL"
cells(i,4).select
ActiveCell.FormulaR1C1 = "=ROUND(RC[-2]*R[-1]C/TOTAL,2)"
cells(i,5).select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-1]C/TOTAL"
cells(i,6).select
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-1]"
cells(i,7).selecr
ActiveCell.FormulaR1C1 = "=RC[-3]"
End If
Loop
next i
Ca marche?
for i =3 to 15
cells(i,1).select
Do cells(i,1)=0
If ActiveCell.Value > 1 Then
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C/TOTAL"
cells(i,4).select
ActiveCell.FormulaR1C1 = "=ROUND(RC[-2]*R[-1]C/TOTAL,2)"
cells(i,5).select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-1]C/TOTAL"
cells(i,6).select
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-1]"
cells(i,7).select
ActiveCell.FormulaR1C1 = "=RC[-3]"
End If
Loop
next i
cells(i,1).select
Do cells(i,1)=0
If ActiveCell.Value > 1 Then
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C/TOTAL"
cells(i,4).select
ActiveCell.FormulaR1C1 = "=ROUND(RC[-2]*R[-1]C/TOTAL,2)"
cells(i,5).select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-1]C/TOTAL"
cells(i,6).select
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-1]"
cells(i,7).select
ActiveCell.FormulaR1C1 = "=RC[-3]"
End If
Loop
next i
pardon
remplace : If ActiveCell.Value > 1 Then
par If selection.value > 1
remplace : If ActiveCell.Value > 1 Then
par If selection.value > 1
Voilà ce que je viens de faire, j'ai supprimé le DO cells(i,1)=0
parce que du coup il me remplace le montant dans la cellule par 0.
For i = 12 To 30
Cells(i, 2).Select
Do
If Selection.Value > 1 Then
Cells(i, 3).Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C/TOTAL"
Cells(i, 4).Select
ActiveCell.FormulaR1C1 = "=ROUND(RC[-2]*R[-1]C/TOTAL,2)"
Cells(i, 5).Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-1]C/TOTAL"
Cells(i, 6).Select
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-1]"
Cells(i, 7).Select
ActiveCell.FormulaR1C1 = "=RC[-3]"
End If
Loop
Next i
End Sub
Et du coup il me fait la macro en boucle...mais que sur la ligne 12 !
il descend pas !!
parce que du coup il me remplace le montant dans la cellule par 0.
For i = 12 To 30
Cells(i, 2).Select
Do
If Selection.Value > 1 Then
Cells(i, 3).Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C/TOTAL"
Cells(i, 4).Select
ActiveCell.FormulaR1C1 = "=ROUND(RC[-2]*R[-1]C/TOTAL,2)"
Cells(i, 5).Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-1]C/TOTAL"
Cells(i, 6).Select
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-1]"
Cells(i, 7).Select
ActiveCell.FormulaR1C1 = "=RC[-3]"
End If
Loop
Next i
End Sub
Et du coup il me fait la macro en boucle...mais que sur la ligne 12 !
il descend pas !!
je ne suis pas bien réveillée :
for i =3 to 15
cells(i,1).select
If ActiveCell.Value > 1 Then
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C/TOTAL"
cells(i,4).select
ActiveCell.FormulaR1C1 = "=ROUND(RC[-2]*R[-1]C/TOTAL,2)"
cells(i,5).select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-1]C/TOTAL"
cells(i,6).select
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-1]"
cells(i,7).select
ActiveCell.FormulaR1C1 = "=RC[-3]"
End If
next i
for i =3 to 15
cells(i,1).select
If ActiveCell.Value > 1 Then
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C/TOTAL"
cells(i,4).select
ActiveCell.FormulaR1C1 = "=ROUND(RC[-2]*R[-1]C/TOTAL,2)"
cells(i,5).select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-1]C/TOTAL"
cells(i,6).select
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-1]"
cells(i,7).select
ActiveCell.FormulaR1C1 = "=RC[-3]"
End If
next i
Ben je peux te dire que si tu es réveillée :) ça marche !! :)
Tu assures Mel' :) !!! Par conter, j'ai une dernière question et après j'arrêtes de t'embêter !!
Tu sais qd il fait les calculs, comment je dois faire pour qu'il prenne toujours la même cellule dans son calcul ? tu sais on met la lettre de la cellule entre $$
exemple $C$12.
Comment ça se manifeste dans une macro ça ?
Je les place ou dans ma formule ?
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C/TOTAL"
Tu assures Mel' :) !!! Par conter, j'ai une dernière question et après j'arrêtes de t'embêter !!
Tu sais qd il fait les calculs, comment je dois faire pour qu'il prenne toujours la même cellule dans son calcul ? tu sais on met la lettre de la cellule entre $$
exemple $C$12.
Comment ça se manifeste dans une macro ça ?
Je les place ou dans ma formule ?
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C/TOTAL"
Bonjour,
ca se manisfeste de la manière suivante.
exemple : si dans ton calcule, ca se base sur C2 :
ActiveCell.FormulaR1C1 = "=R2C3"
se base sur A4
ActiveCell.FormulaR1C1 = "=R4C1"
multiplier c2 par A4
ActiveCell.FormulaR1C1 = "=R2C3*R4C1"
R pour la ligne et C pour la colonne.
ca se manisfeste de la manière suivante.
exemple : si dans ton calcule, ca se base sur C2 :
ActiveCell.FormulaR1C1 = "=R2C3"
se base sur A4
ActiveCell.FormulaR1C1 = "=R4C1"
multiplier c2 par A4
ActiveCell.FormulaR1C1 = "=R2C3*R4C1"
R pour la ligne et C pour la colonne.
Ok ça marche bien là c'est nickel !!!!
Juste une dernière chose !! Ma dernieère cellule en bas, c'est le total (c'est d'ailleurs, comme tu as pu le constater repris dans les formule "TOTAL")
Comment faire pour qu'en fait la macro s'arrête qd il est arrivé à TOTAL, en fait je ne veuxpas qu'il me fasse de calcul arrivé sur cette cellule
Juste une dernière chose !! Ma dernieère cellule en bas, c'est le total (c'est d'ailleurs, comme tu as pu le constater repris dans les formule "TOTAL")
Comment faire pour qu'en fait la macro s'arrête qd il est arrivé à TOTAL, en fait je ne veuxpas qu'il me fasse de calcul arrivé sur cette cellule
Alors il faut modifier ton code :
i=3
cells(i,1).select
do while cells(i,1) <> "TOTAL"
If ActiveCell.Value > 1 Then
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C/TOTAL"
cells(i,4).select
ActiveCell.FormulaR1C1 = "=ROUND(RC[-2]*R[-1]C/TOTAL,2)"
cells(i,5).select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-1]C/TOTAL"
cells(i,6).select
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-1]"
cells(i,7).select
ActiveCell.FormulaR1C1 = "=RC[-3]"
End If
i=i+1
cells(i,1).select
loop
i=3
cells(i,1).select
do while cells(i,1) <> "TOTAL"
If ActiveCell.Value > 1 Then
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C/TOTAL"
cells(i,4).select
ActiveCell.FormulaR1C1 = "=ROUND(RC[-2]*R[-1]C/TOTAL,2)"
cells(i,5).select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-1]C/TOTAL"
cells(i,6).select
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-1]"
cells(i,7).select
ActiveCell.FormulaR1C1 = "=RC[-3]"
End If
i=i+1
cells(i,1).select
loop
Ok alors là moi je dis RESPECT !!
Si ensuite je fais une mise en forme des cellules via la macro (je vais rajouter des trucs comme quoi je veux 2 chiffres apres la virgule et les montants espacés, et aussi des bordures, est ce que je peux arrêter cette mise en forme à TOTAL ? c'est à dire ne pas aller + loin que TOTAL ?
Si ensuite je fais une mise en forme des cellules via la macro (je vais rajouter des trucs comme quoi je veux 2 chiffres apres la virgule et les montants espacés, et aussi des bordures, est ce que je peux arrêter cette mise en forme à TOTAL ? c'est à dire ne pas aller + loin que TOTAL ?
Bien sur, il suffit de mettre ton code correspondant à la mise en forme entre le do et le loop.
Ca ne fonctionne plus !! Je ne sais aps pourquoi !!
Mais je pense que c'est à cause de "TOTAL" tu sais c'est pas écrit "TOTAL" dans la cellule, c'est juste que j'ai remplacé le nom de la cellule B23 par "TOTAL"
regarde la macro :
i = 12
Cells(i, 2).Select
Do While Cells(i, 2) = "TOTAL"
If ActiveCell.Value > 1 Then
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C/TOTAL"
Cells(i, 4).Select
ActiveCell.FormulaR1C1 = "=ROUND(RC[-2]*R[-1]C/TOTAL,2)"
Cells(i, 5).Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-1]C/TOTAL"
Cells(i, 6).Select
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-1]"
Cells(i, 7).Select
ActiveCell.FormulaR1C1 = "=RC[-3]"
End If
Range("C12:G12").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Selection.NumberFormat = "#,##0.00"
Range("C12").Select
i = i + 1
Cells(i, 1).Select
Loop
End Sub
Mais je pense que c'est à cause de "TOTAL" tu sais c'est pas écrit "TOTAL" dans la cellule, c'est juste que j'ai remplacé le nom de la cellule B23 par "TOTAL"
regarde la macro :
i = 12
Cells(i, 2).Select
Do While Cells(i, 2) = "TOTAL"
If ActiveCell.Value > 1 Then
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C/TOTAL"
Cells(i, 4).Select
ActiveCell.FormulaR1C1 = "=ROUND(RC[-2]*R[-1]C/TOTAL,2)"
Cells(i, 5).Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-1]C/TOTAL"
Cells(i, 6).Select
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-1]"
Cells(i, 7).Select
ActiveCell.FormulaR1C1 = "=RC[-3]"
End If
Range("C12:G12").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Selection.NumberFormat = "#,##0.00"
Range("C12").Select
i = i + 1
Cells(i, 1).Select
Loop
End Sub
Re,
Ce code marche si tu as défini une plage de cellule comme étant total :
i = 12
Cells(i, 2).Select
Do While i< range("total").row
If ActiveCell.Value > 1 Then
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C/TOTAL"
Cells(i, 4).Select
ActiveCell.FormulaR1C1 = "=ROUND(RC[-2]*R[-1]C/TOTAL,2)"
Cells(i, 5).Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-1]C/TOTAL"
Cells(i, 6).Select
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-1]"
Cells(i, 7).Select
ActiveCell.FormulaR1C1 = "=RC[-3]"
End If
Range("C12:G12").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Selection.NumberFormat = "#,##0.00"
Range("C12").Select
i = i + 1
Cells(i, 1).Select
Loop
Ce code marche si tu as défini une plage de cellule comme étant total :
i = 12
Cells(i, 2).Select
Do While i< range("total").row
If ActiveCell.Value > 1 Then
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C/TOTAL"
Cells(i, 4).Select
ActiveCell.FormulaR1C1 = "=ROUND(RC[-2]*R[-1]C/TOTAL,2)"
Cells(i, 5).Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-1]C/TOTAL"
Cells(i, 6).Select
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-1]"
Cells(i, 7).Select
ActiveCell.FormulaR1C1 = "=RC[-3]"
End If
Range("C12:G12").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Selection.NumberFormat = "#,##0.00"
Range("C12").Select
i = i + 1
Cells(i, 1).Select
Loop
i = 12
Cells(i, 2).Select
Do While cells(i,1)<> ""
If ActiveCell.Value > 1 Then
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C/TOTAL"
Cells(i, 4).Select
ActiveCell.FormulaR1C1 = "=ROUND(RC[-2]*R[-1]C/TOTAL,2)"
Cells(i, 5).Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-1]C/TOTAL"
Cells(i, 6).Select
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-1]"
Cells(i, 7).Select
ActiveCell.FormulaR1C1 = "=RC[-3]"
End If
Range(cells(i,3),cells(i,7)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Selection.NumberFormat = "#,##0.00"
i = i + 1
Cells(i, 1).Select
Loop
cells(i,4).select
ActiveCell.FormulaR1C1 = "=SUM(R12C:R[-1]C)"
selection.select
ActiveWorkbook.Names("total").Delete
Selection.Name = "total"
Cells(i, 2).Select
Do While cells(i,1)<> ""
If ActiveCell.Value > 1 Then
ActiveCell.FormulaR1C1 = "=RC[-1]*R[-1]C/TOTAL"
Cells(i, 4).Select
ActiveCell.FormulaR1C1 = "=ROUND(RC[-2]*R[-1]C/TOTAL,2)"
Cells(i, 5).Select
ActiveCell.FormulaR1C1 = "=RC[-3]*R[-1]C/TOTAL"
Cells(i, 6).Select
ActiveCell.FormulaR1C1 = "=RC[-3]-RC[-1]"
Cells(i, 7).Select
ActiveCell.FormulaR1C1 = "=RC[-3]"
End If
Range(cells(i,3),cells(i,7)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Selection.NumberFormat = "#,##0.00"
i = i + 1
Cells(i, 1).Select
Loop
cells(i,4).select
ActiveCell.FormulaR1C1 = "=SUM(R12C:R[-1]C)"
selection.select
ActiveWorkbook.Names("total").Delete
Selection.Name = "total"
Serieux tu assures !!!!!!
Comment faire pourque : au lieu d'arrêter la macro à "TOTAL", ben en fait elle s'arrête
quand la case est vide ?
Parce qu'en fait, là tout est nickel, mais par exemple si j'insère une ligne en +, du coup il s'arrête à TOTAL !