iStarOSX
XLDnaute Junior
Bonjour a tous.
Voila j'ai un petit tableau qui comporte une cellule "valeur total" qui porte bien son nom puisqu'elle comporte la valeur total de mon calcul.
Ensuite j'ai 2 colonnes, la première qui comporte les "%" et la seconde la valeur qui correspond au pourcentage.
Je cherche a faire une macro qui, lorsque l'on remplis un pourcentage, calcul la valeur et rempli la colonne valeur, et inversement si l'on saisi directement la valeur, le pourcentage soit calculé et rempli.
J'ai fait se bout de code, mais il tourne en boucle est fait planter Excel.
Je joint un fichier exemple, mais ATTENTION ma macro fait planté excel.
Si quelqu'un peut me dire se qui ne va pas dans mon code, je vous en remercie d'avance.
Voila j'ai un petit tableau qui comporte une cellule "valeur total" qui porte bien son nom puisqu'elle comporte la valeur total de mon calcul.
Ensuite j'ai 2 colonnes, la première qui comporte les "%" et la seconde la valeur qui correspond au pourcentage.
Je cherche a faire une macro qui, lorsque l'on remplis un pourcentage, calcul la valeur et rempli la colonne valeur, et inversement si l'on saisi directement la valeur, le pourcentage soit calculé et rempli.
J'ai fait se bout de code, mais il tourne en boucle est fait planter Excel.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'=========================================================================================================================================================
'POURCENTAGE:
If Application.Intersect(Target, Range("G18")) Is Nothing Then
Sheets("Sélection").Range("K18").ClearContents
Sheets("Sélection").Range("K18").FormulaR1C1 = "=R7C18*RC[-4]/100"
End If
If Not Application.Intersect(Target, Range("G19")) Is Nothing Then
Sheets("Sélection").Range("K19").ClearContents
Sheets("Sélection").Range("K19").FormulaR1C1 = "=R7C18*RC[-4]/100"
Application.ScreenUpdating = True
End If
If Not Application.Intersect(Target, Range("G20")) Is Nothing Then
Sheets("Sélection").Range("K20").ClearContents
Sheets("Sélection").Range("K20").FormulaR1C1 = "=R7C18*RC[-4]/100"
End If
If Not Application.Intersect(Target, Range("G21")) Is Nothing Then
Sheets("Sélection").Range("K21").ClearContents
Sheets("Sélection").Range("K21").FormulaR1C1 = "=R7C18*RC[-4]/100"
End If
'=========================================================================================================================================================
'valeur:
If Application.Intersect(Target, Range("K18")) Is Nothing Then
Sheets("Sélection").Range("G18").ClearContents
Sheets("Sélection").Range("G18").FormulaR1C1 = "=100/R7C18*RC[4]"
End If
If Not Application.Intersect(Target, Range("K19")) Is Nothing Then
Sheets("Sélection").Range("G20").ClearContents
Sheets("Sélection").Range("G19").FormulaR1C1 = "=100/R7C18*RC[4]"
Application.ScreenUpdating = True
End If
If Not Application.Intersect(Target, Range("K20")) Is Nothing Then
Sheets("Sélection").Range("G20").ClearContents
Sheets("Sélection").Range("G20").FormulaR1C1 = "=100/R7C18*RC[4]"
End If
If Not Application.Intersect(Target, Range("K21")) Is Nothing Then
Sheets("Sélection").Range("G21").ClearContents
Sheets("Sélection").Range("G21").FormulaR1C1 = "=100/R7C18*RC[4]"
End If
End Sub
Je joint un fichier exemple, mais ATTENTION ma macro fait planté excel.
Si quelqu'un peut me dire se qui ne va pas dans mon code, je vous en remercie d'avance.