pb avec une macro

A

AIZ

Guest
bonjour,

la macro suivante ne marche que si l'on indique le pourcentage de AK2 et l'on a en automatique AK3 or si je cherche AK2 et que j'ai déja le pourcentage de AK3 alors cela ne marche pas.

Quelqu'un aurai il une solution?

Sub pourcent()
colak = Range('AK1').Column
For Each c In Range('C3:C5249')
tot = 0
If c = Cells(c.Row - 1, c.Column) And Cells(c.Row, colak) = '' Then
For n = 1 To 10
If Cells(c.Row - n, c.Column) = c Then
tot = tot + Cells(c.Row - n, colak)
Else
Cells(c.Row, colak) = 100 - tot
Exit For
End If
Next
End If
Next
End Sub
 

pierrejean

XLDnaute Barbatruc
peux-tu tester ceci
(à partir de la cellule ou le pourcentage manque on controle vers le haut puis vers le bas)
je crains cependant que sur la totalité des lignes la macro soit un peu longue
qu'en est-il de la solution precedant la mienne ?

Sub pourcent()
colak = Range('AK1').Column
For Each c In Range('C3:C5249')
tot = 0
If c = Cells(c.Row - 1, c.Column) And Cells(c.Row, colak) = '' Then
For n = 1 To 10
If Cells(c.Row - n, c.Column) = c Then
tot = tot + Cells(c.Row - n, colak)
Else
Exit For
End If
Next

For n = 1 To 10
If Cells(c.Row + n, c.Column) = c Then
tot = tot + Cells(c.Row + n, colak)
Else
Cells(c.Row, colak) = 100 - tot
Exit For
End If
Next
End If
Next
End Sub
 
A

aiz

Guest
merci porcinet

voila [file name=exforumexcel.zip size=14206]http://www.excel-downloads.com/components/com_simpleboard/uploaded/files/exforumexcel.zip[/file]
 

Pièces jointes

  • exforumexcel.zip
    13.9 KB · Affichages: 15

pierrejean

XLDnaute Barbatruc
rien ne vaut un exemple concret !!
teste ceci stp
Sub pourcent()
colak = Range('AK1').Column
For Each c In Range('C3:C5249')
tot = 0
If Cells(c.Row, colak) = '' Then
For n = 1 To 10
If Cells(c.Row - n, c.Column) = c Then
tot = tot + Cells(c.Row - n, colak)
Else
Exit For
End If
Next

For n = 1 To 10
If Cells(c.Row + n, c.Column) = c Then
tot = tot + Cells(c.Row + n, colak)
Else
Cells(c.Row, colak) = 100 - tot
Exit For
End If
Next
End If
Next
End Sub [file name=exforumexcel1.zip size=16946]http://www.excel-downloads.com/components/com_simpleboard/uploaded/files/exforumexcel1.zip[/file]
 

Pièces jointes

  • exforumexcel1.zip
    16.5 KB · Affichages: 14

Discussions similaires

Réponses
3
Affichages
600

Statistiques des forums

Discussions
312 413
Messages
2 088 201
Membres
103 766
dernier inscrit
mahieux