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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
Sub test3()
' // Resultat pourrait être un tableau pour y stocker toutes les valeurs
Dim Resultat As Double, Ligne As Long, LigneDeSomme As Range, MaxColonneJ As Long
Dim plg As Range, i As Long
Resultat = 0
Ligne = 1
' // On définit la plage de recherche
Set plg = Worksheets("Feuil5").Range("J" & Ligne & ":J" & Range("J" & Rows.Count).End(xlUp).Row)
' // The settings for LookIn, LookAt, SearchOrder, and MatchByte are saved each time you use this method.
' // If you do not specify values for these arguments the next time you call the method,
' // the saved values are used. Setting these arguments changes the settings in the Find dialog box,
' // and changing the settings in the Find dialog box changes the saved values that are used if you omit the arguments.
' // To avoid problems, set these arguments explicitly each time you use this method.
' // On recherche la première somme
With plg
Debug.Print "Adresse de la plage : " & .Address
' // On prends le problème à l'envers
' // je recherche la première formule de somme c'est une méthode comme une autre
Set LigneDeSomme = .Find(What:="=SUM", LookAt:=xlPart, Lookin:=xlFormulas, SearchDirection:=xlNext)
' // DerniereLigne peut être = a Nothing donc tu dois faire un test
' // If Not DerniereLigne Is Nothing Then
If Not LigneDeSomme Is Nothing Then
Dim FirstAddress As String
FirstAddress = LigneDeSomme.Address
Debug.Print "Première adresse trouvée : " & FirstAddress
Do
Resultat = LigneDeSomme.Value - WorksheetFunction.Max(Range("J" & Ligne & ":J" & LigneDeSomme.Offset(-1, 0).Row))
Debug.Print "Valeur max de la plage = " & WorksheetFunction.Max(Range("J" & Ligne & ":J" & LigneDeSomme.Offset(-1, 0).Row))
Debug.Print "Résultat de la somme moins la valeur max pour la plage J" & Ligne & ":J" & LigneDeSomme.Offset(-1, 0).Row & " = " & Resultat
Ligne = LigneDeSomme.Offset(3, 0).Row
Set LigneDeSomme = .FindNext(LigneDeSomme)
Loop While Not (LigneDeSomme Is Nothing) And FirstAddress <> LigneDeSomme.Address
Else
MsgBox "Pas de Données à traiter"
End If
End With
End Sub |
Partager