1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| Function SerchXls(Myrange As Range, MyCellule As Range, strRecherche, EntierCell As Boolean) As Long '
On Error Resume Next
Dim CellEntrier As Integer
If EntierCell = True Then CellEntrier = xlWhole Else CellEntrier = xlPart
SerchXls = 0
SerchXls = Myrange.Cells.Find(what:=strRecherche, After:=MyCellule, LookIn:=xlFormulas, LookAt _
:=CellEntrier, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=EntierCell).Row
If SerchXls <= MyCellule.Row Then SerchXls = 0
End Function
Function AditionValeur(strRecherche, Myrange As Range) As Double
Dim R As Long
R = 1
While R > 0
R = SerchXls(Myrange, Myrange(R, 1), strRecherche, True)
If R > 0 Then AditionValeur = AditionValeur + Myrange(R, 1).Offset(0, 2)
Wend
End Function
Sub Main()
With Sheets("données")
R = .Cells(.Cells.Rows.Count, "A").End(xlUp).Row
.Range(.Cells(2, "B"), .Cells(R, "B")).FormulaR1C1 = "=AditionValeur(RC[-1],Feuil1!R[-1]C:R[147]C)"
.Range(.Cells(2, "B"), .Cells(R, "B")).Value = .Range(.Cells(2, "B"), .Cells(R, "B")).Value
End With
End Sub |
Partager