IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Calcul de distances parcourues en commun


Sujet :

Macros et VBA Excel

  1. #61
    Membre chevronné
    Inscrit en
    Septembre 2007
    Messages
    1 134
    Détails du profil
    Informations forums :
    Inscription : Septembre 2007
    Messages : 1 134
    Points : 1 808
    Points
    1 808
    Par défaut
    Bonjour Klin89,
    Citation Envoyé par Klin89 Voir le message
    anasecu, dans le fichier du post #53#, tu n'as pas mis le nouveau code
    Tu as raison je me suis trompé de classeur, voilà le dernier code et classeur.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    Option Explicit
    Dim idd As Long
    Dim ide As Long
    Dim idr As Long
    Dim nom As String
    Dim mfn As Byte
    Dim tmf(2)
    Dim tbd
    Dim tbe
    Dim tbr
    Dim elm
    Public Sub Calculs()
        With ActiveSheet
            .Cells(2, 6).Resize(.Cells(Rows.Count, 13).End(xlUp).Row, 10).ClearContents
            Call parcours
            Call résultat
            Call mfc
        End With
    End Sub
    Public Sub résultat()
    Dim eec As String, nec As Byte, nkm As Double, pkm As Double, nok As Boolean
        idr = 1: mfn = 0: tmf(0) = "=OU(": tmf(1) = "=OU("
        For ide = 2 To UBound(tbe)
            eec = "|*" & tbe(ide, 1) & "*": nec = 0: mfn = IIf(mfn, 0, 1): nok = False: nkm = 0: pkm = 0
            tmf(mfn) = tmf(mfn) & IIf(Len(tmf(mfn)) > 4, ";", "") & "$H2=""" & tbe(ide, 1) & """"
            For idd = 1 To UBound(tbd) - 1
                elm = Split(tbd(idd), "*")
                If elm(1) = "/" Then
                    nec = nec + 1
                    If InStr(eec, elm(2) & "*") = 0 Then eec = eec & "|*" & elm(2) & "*"
                    If elm(2) = tbe(ide, 1) Then nok = True
                Else
                    nec = nec - 1: eec = Replace(eec, "|*" & elm(2) & "*", "")
                End If
                If nok Then
                    tbr(idr, 1) = Split(tbd(idd + 1) & "*", "*")(0) - Split(tbd(idd) & "*", "*")(0)
                    tbr(idr, 2) = Split(tbd(idd) & "*", "*")(0) & " à " & Split(tbd(idd + 1) & "*", "*")(0)
                    nkm = nkm + tbr(idr, 1)
                    tbr(idr, 3) = tbe(ide, 1)
                    tbr(idr, 4) = nec
                    tbr(idr, 5) = RTrim(Replace(Mid(eec, 3), "*", " "))
                    tbr(idr, 7) = tbe(ide, 4)
                    tbr(idr, 8) = IIf(nec = 1, 0.1, IIf(nec = 2, 0.23, 0.37))
                    tbr(idr, 9) = tbr(idr, 1) * tbr(idr, 7) * (1 - tbr(idr, 8))
                    pkm = pkm + tbr(idr, 9)
                    If tbr(idr, 1) > 0 Then idr = idr + 1
                    If Split(tbd(idd + 1) & "*", "*")(2) = tbe(ide, 1) And Split(tbd(idd + 1) & "*", "*")(1) = "\" Then
                        tbr(idr - 1, 6) = nkm
                        tbr(idr - 1, 10) = pkm
                        Exit For
                    End If
                End If
            Next idd
        Next ide
        ActiveSheet.[F2].Resize(idr - 1, UBound(tbr, 2)).Value = tbr
    End Sub
    Public Sub parcours()
        tbe = ActiveSheet.Range("A1").CurrentRegion.Value
        ReDim tbd(1 To 1)
        For ide = 2 To UBound(tbe)
            If Not IsNumeric(tbe(ide, 2)) Or tbe(ide, 2) = "" _
                Or Not IsNumeric(tbe(ide, 3)) Or tbe(ide, 3) = "" _
                Or tbe(ide, 3) <= tbe(ide, 2) Then
                    MsgBox "Donnée PK incorrecte pour " & tbe(ide, 1): End
            End If
            tbd(UBound(tbd)) = tbe(ide, 2) & "*/*" & tbe(ide, 1)
            ReDim Preserve tbd(1 To UBound(tbd) + 1)
            tbd(UBound(tbd)) = tbe(ide, 3) & "*\*" & tbe(ide, 1)
            ReDim Preserve tbd(1 To UBound(tbd) + 1)
        Next ide
        For ide = 1 To UBound(tbd) - 1
            For idd = ide To UBound(tbd) - 1
                If CDbl(Left(tbd(ide), InStr(tbd(ide), "*") - 1)) > CDbl(Left(tbd(idd), InStr(tbd(idd), "*") - 1)) Then
                    nom = tbd(ide): tbd(ide) = tbd(idd): tbd(idd) = nom
                End If
            Next idd
        Next ide
        ReDim tbr(1 To UBound(tbe) * 15, 1 To 10)
    End Sub
    Sub mfc()
        With ActiveSheet
            .Cells(2, 5).Activate
            With .Cells(2, 6).Resize(.Cells(Rows.Count, 13).End(xlUp).Row, 10)
                .FormatConditions.Delete
                .FormatConditions.Add Type:=xlExpression, Formula1:=tmf(1) & ")"
                With .FormatConditions(1).Interior
                    .PatternColorIndex = xlAutomatic
                    .ColorIndex = 44
                End With
                If Len(tmf(0)) > 4 Then
                    .FormatConditions.Add Type:=xlExpression, Formula1:=tmf(0) & ")"
                    With .FormatConditions(2).Interior
                        .PatternColorIndex = xlAutomatic
                        .ColorIndex = 39
                    End With
                End If
            End With
        End With
    End Sub
    Fichiers attachés Fichiers attachés

  2. #62
    Expert confirmé
    Homme Profil pro
    PAO
    Inscrit en
    Octobre 2014
    Messages
    2 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : PAO
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Octobre 2014
    Messages : 2 576
    Points : 4 176
    Points
    4 176
    Par défaut
    Hi Klin89,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    RyuAutodidacte : post #56#  y'a pas de S à Lacour dans mon exemple
    ne t'inquiète pas je ne suis pas aveugle, d'ailleurs je t'avais fait un Edit 2 avant que tu posts => ICI

    Donc voilà, mon code était un peu condensé, donc tout en gardant le même mécanisme je l'ai repris de Zéro, ça m'a permis de faire un peu le ménage,
    et d'améliorer certaines parties.

    Du coup dans un 1er temps, je n'ai refais que la base (pour que tu puisses tester) sans les différentes options (je ferai celles-ci par la suite)

    Donc pour le test rien de plus simple, mettre son tableau à partir de A1 puis lancer le code.

    PS : je pense (enfin je l'espère) en avoir bien fini avec les Jean, Jeanine, Lacour, etc…

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    Option Explicit
     
    Sub NewFinalSansOption()
    Dim Res, Abatt, DL As Long, VA, i As Long, j As Long, Tab_Pk(), TPK(), Coll_PK As New Collection, PK, nom$, L As Integer, Som As Double
     
        Res = Application.Transpose(Array("Distance PK en Km", "PK", "Elève", "Nb élèves", "Elèves communs", "Total Km/élève", "Tarif", "Abattement", "Montant facturé", "Montant total/élève"))
        Abatt = Array("10%", "23%", "37%")
     
        With Range("A1").CurrentRegion
            DL = .Rows.Count
            VA = .Value
     
            Tab_Pk = Application.Index(VA, Evaluate("Row(2:" & DL & ")"), Array(2, 3))
            For i = 1 To UBound(Tab_Pk)
                If Tab_Pk(i, 2) - Tab_Pk(i, 1) <= 0 Then MsgBox "Données PK non coformes pour " & VA(i + 1, 1):    Exit Sub
            Next
    On Error Resume Next ' --------------------------------------------------------------------------------------------------------------
            For i = 1 To (DL - 1) * 2
                Coll_PK.Add Application.Small(Tab_Pk, i), CStr(Application.Small(Tab_Pk, i))
                If Err Then Err.Clear Else j = j + 1:    ReDim Preserve TPK(1 To j):    TPK(j) = Coll_PK(CStr(Application.Small(Tab_Pk, i)))
            Next
            Set Coll_PK = Nothing
     
            For i = 2 To UBound(TPK)
                If TPK(i) > TPK(i - 1) Then
                    PK = TPK(i - 1) & " à " & TPK(i)
                    For j = 2 To DL
                        If VA(j, 2) <= TPK(i - 1) And VA(j, 3) >= TPK(i) Then
                            Coll_PK.Add "|" & VA(j, 1) & "|", PK
                            If Not Err Then Err.Clear:      If InStr(Coll_PK(PK), VA(j, 1) & "|") = 0 Then nom = Coll_PK(PK): Coll_PK.Remove PK:        Coll_PK.Add nom & "|" & VA(j, 1) & "|", PK
                        End If
                    Next
                End If
            Next
    On Error GoTo 0 ' -------------------------------------------------------------------------------------------------------------------
     
            For i = 2 To DL
                j = 1
                For Each PK In Coll_PK
                    Debug.Print Len(PK)
                    j = j + 1
                    If InStr(PK, "|" & VA(i, 1) & "|") > 0 Then
                        ReDim Preserve Res(1 To 10, 1 To UBound(Res, 2) + 1): nom = Replace(Mid("|" & VA(i, 1) & "|" & Replace(PK, "|" & VA(i, 1) & "|", ""), 2, Len(PK) - 2), "||", " | "): L = UBound(Res, 2)
                        Res(1, L) = TPK(j) - TPK(j - 1):    Res(2, L) = TPK(j - 1) & " à " & TPK(j): Res(3, L) = VA(i, 1):    Res(4, L) = Len(nom) - Len(Replace(nom, "|", "")) + 1:  Res(5, L) = nom
                        Res(7, L) = VA(i, 4):       Res(8, L) = Abatt(IIf(Res(4, L) > 2, 2, Res(4, L) - 1)):        Res(9, L) = Res(1, L) * VA(i, 4) * (1 - (Val(Res(8, L)) / 100)):        Som = Som + Res(9, L)
                    End If
                Next
                Res(6, L) = VA(i, 3) - VA(i, 2):        Res(10, L) = Som:       Som = 0
            Next
    Application.ScreenUpdating = False ' -------------------------------------------------------------------------------------------------------------------
            With .Offset(, .Columns.Count + 3).Resize(1, 1)
              .CurrentRegion.Clear
                .Resize(UBound(Res, 2), UBound(Res)) = Application.Transpose(Res)
                With .CurrentRegion
                    .HorizontalAlignment = xlCenter:        .VerticalAlignment = xlCenter:  .Columns.AutoFit
                    New_inter_Coul 2, .Cells, 3
                    .Borders.Value = 1
                End With
            End With
    Application.ScreenUpdating = True ' -------------------------------------------------------------------------------------------------------------------
        End With
    End Sub
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    Function New_inter_Coul(Deb As Byte, Rg As Range, Col As Byte) 'RyuAutodidacte - code réadapté pour ce post
    Dim Cpt As Long, indx As Long, Coul(), Cel As Range
    Cpt = 1:    indx = 1:       Coul() = Array(15, 44) ' Possibilité de modifier/ajouter/enlever des couleurs index dans l'Array
        Application.ScreenUpdating = False
            For Each Cel In Rg.Columns.Item(Col).Offset(1).Resize(Rg.Rows.Count - Deb + 1).Rows
                If Cel = Cel.Offset(1) Then
                    Cpt = Cpt + 1
                Else
                    Rg.Rows(Deb).Resize(Cpt).Interior.ColorIndex = Coul(indx Mod (UBound(Coul) + 1))
                    Deb = Deb + Cpt: Cpt = 1: indx = indx + 1
                End If
            Next
        Application.ScreenUpdating = True
    End Function
    'Cf =>https://www.developpez.net/forums/d1878159/logiciels/microsoft-office/excel/macros-vba-excel/alterner-couleurs/
    Voilà, j'attends ton retour

    PS : je vais regarder pour le Application.InputBox, mais si tu as des infos (ou bien même les participants de ce post) fais/faites signe

    E d i t :

    La procédure suivante utilisée pour sélectionner une plage de cellule provoque parfois une erreur et sans que vous puissiez exactement déterminer la cause.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    Dim Source As Range
     
    Set Source = Application.InputBox("Sélectionnez une plage de cellules : ", , , , , , , 8)
    MsgBox Source.Address
    Vérifiez si les cellules qui posent problème contiennent des mises en forme conditionnelles de type "la formule est".
    C'est un bug connu de la méthode Application.InputBox jusqu'à Excel 2003. Application.InputBox ne renvoie rien dans ce cas et provoque une erreur dans la suite de la procédure.

    Nota:
    Le problème est résolu dans Excel 2007.
    Créé le 20 septembre 2008 par SilkyRoad


    Edit suite :
    il serait intéressant de tester mon code avec Application.InputBox sur un fichier vierge n'ayant pas de MFC …
    Sinon le code Ok est celui ci-dessus, je repasserai pour rajouter les options …

  3. #63
    Membre habitué Avatar de Klin89
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    119
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 119
    Points : 178
    Points
    178
    Par défaut
    Bonsoir à tous,

    Je pense avoir fait le tour

    anasecu, c'est le top

    RyuAutodidacte, y'a un petit bug ici

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Tab_Pk = Application.Index(VA, Evaluate("Row(2:" & DL & ")"), Array(2, 3))
    Tab_Pk renvoie un tableau à 1 dimension lorsqu'il n'y qu'une seule ligne à traiter.

    Sinon j'obtiens les mêmes résultats qu'anasecu
    Concernant Application.InputBox, cela me renvoie toujours nothing même sans MFC, je n'ai pas cherché plus loin
    Pour moi, le sujet est clos, merci à vous tous

    klin89

  4. #64
    Expert confirmé
    Homme Profil pro
    PAO
    Inscrit en
    Octobre 2014
    Messages
    2 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : PAO
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Octobre 2014
    Messages : 2 576
    Points : 4 176
    Points
    4 176
    Par défaut
    Hi Klin89,

    Bien vu pour le bug - je vais t'appeler The hunter of bugs

    Voilà c'est réglé :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    Sub NewFinalSansOption()
    Dim Res, Abatt, DL As Long, VA, i As Long, j As Long, Tab_Pk(), TPK(), Coll_PK As New Collection, PK, nom$, L As Integer, Som As Double
     
        Res = Application.Transpose(Array("Distance PK en Km", "PK", "Elève", "Nb élèves", "Elèves communs", "Total Km/élève", "Tarif", "Abattement", "Montant facturé", "Montant total/élève"))
        Abatt = Array("10%", "23%", "37%")
     
        With Range("A1").CurrentRegion
            DL = .Rows.Count
            VA = .Value
            Tab_Pk = Application.Index(VA, Evaluate("Row(2:" & DL & ")"), Array(2, 3))
            For i = 2 To DL
                If VA(i, 3) - VA(i, 2) <= 0 Then MsgBox "Données PK non coformes pour " & VA(i + 1, 1): Exit Sub
            Next
     
    On Error Resume Next ' --------------------------------------------------------------------------------------------------------------
            For i = 1 To (DL - 1) * 2
                Coll_PK.Add Application.Small(Tab_Pk, i), CStr(Application.Small(Tab_Pk, i))
                If Err Then Err.Clear Else j = j + 1:    ReDim Preserve TPK(1 To j):    TPK(j) = Coll_PK(CStr(Application.Small(Tab_Pk, i)))
            Next
            Set Coll_PK = Nothing
     
            For i = 2 To UBound(TPK)
                If TPK(i) > TPK(i - 1) Then
                    PK = TPK(i - 1) & " à " & TPK(i)
                    For j = 2 To DL
                        If VA(j, 2) <= TPK(i - 1) And VA(j, 3) >= TPK(i) Then
                            Coll_PK.Add "|" & VA(j, 1) & "|", PK
                            If Not Err Then Err.Clear:      If InStr(Coll_PK(PK), VA(j, 1) & "|") = 0 Then nom = Coll_PK(PK): Coll_PK.Remove PK:        Coll_PK.Add nom & "|" & VA(j, 1) & "|", PK
                        End If
                    Next
                End If
            Next
    On Error GoTo 0 ' -------------------------------------------------------------------------------------------------------------------
     
            For i = 2 To DL
                j = 1
                For Each PK In Coll_PK
                    Debug.Print Len(PK)
                    j = j + 1
                    If InStr(PK, "|" & VA(i, 1) & "|") > 0 Then
                        ReDim Preserve Res(1 To 10, 1 To UBound(Res, 2) + 1): nom = Replace(Mid("|" & VA(i, 1) & "|" & Replace(PK, "|" & VA(i, 1) & "|", ""), 2, Len(PK) - 2), "||", " | "): L = UBound(Res, 2)
                        Res(1, L) = TPK(j) - TPK(j - 1):    Res(2, L) = TPK(j - 1) & " à " & TPK(j): Res(3, L) = VA(i, 1):    Res(4, L) = Len(nom) - Len(Replace(nom, "|", "")) + 1:  Res(5, L) = nom
                        Res(7, L) = VA(i, 4):       Res(8, L) = Abatt(IIf(Res(4, L) > 2, 2, Res(4, L) - 1)):        Res(9, L) = Res(1, L) * VA(i, 4) * (1 - (Val(Res(8, L)) / 100)):        Som = Som + Res(9, L)
                    End If
                Next
                Res(6, L) = VA(i, 3) - VA(i, 2):        Res(10, L) = Som:       Som = 0
            Next
    Application.ScreenUpdating = False ' -------------------------------------------------------------------------------------------------------------------
            With .Offset(, .Columns.Count + 3).Resize(1, 1)
              .CurrentRegion.Clear
                .Resize(UBound(Res, 2), UBound(Res)) = Application.Transpose(Res)
                With .CurrentRegion
                    .HorizontalAlignment = xlCenter:        .VerticalAlignment = xlCenter:  .Columns.AutoFit
                    New_inter_Coul 2, .Cells, 3
                    .Borders.Value = 1
                End With
            End With
    Application.ScreenUpdating = True ' -------------------------------------------------------------------------------------------------------------------
        End With
    End Sub
    Comme le sujet est clos, je ne pense pas que les options que j'avais fait via le InputBox t'intéresse !!?? (je serais passé par un autre moyen)

    En tout cas sujet intéressant et pour la chasse aux bugs

    PS : en tout cas on sait maintenant que Excel 2003 peut bugguer avec Application.InputBox

    Amicalement Ryu

    Edit : Corr. orthographe.

  5. #65
    Expert confirmé
    Homme Profil pro
    PAO
    Inscrit en
    Octobre 2014
    Messages
    2 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : PAO
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Octobre 2014
    Messages : 2 576
    Points : 4 176
    Points
    4 176
    Par défaut
    Re,

    Aller comme c'était rapide à faire (reprise une petite partie de mon ancien code), je l'ai fait avec 1 Option

    - plus besoin de se mettre en A1 on sélectionne le tableau (1 ou plusieurs cellule du tableau) puis on envoi le code

    - l'Option : sélectionne une cellule contenant le nom d'un élève puis envoi le code, tu verras …
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    Sub PK_Avec_UneOption()
    Dim Res, Abatt, TB_Source As Range, DL As Long, VA, i As Long, j As Long, X As Integer, Tab_Pk(), TPK(), Coll_PK As New Collection, PK, nom$, L As Integer, Som As Double
     
        Res = Application.Transpose(Array("Distance PK en Km", "PK", "Elève", "Nb élèves", "Elèves communs", "Total Km/élève", "Tarif", "Abattement", "Montant facturé", "Montant total/élève"))
        Abatt = Array("10%", "23%", "37%")
     
        Set TB_Source = Selection
        With TB_Source.CurrentRegion
            If Application.CountBlank(.Cells) >= 1 Then MsgBox "DONNÉES MANQUANTES" & vbCrLf & vbCrLf & "Vérifier votre tableau source !!!!!!!": Set TB_Source = Nothing: Exit Sub
            DL = .Rows.Count
            VA = .Value
            Tab_Pk = Application.Index(VA, Evaluate("Row(2:" & DL & ")"), Array(2, 3))
            For i = 2 To DL
                If VA(i, 3) - VA(i, 2) <= 0 Then MsgBox "Données PK non coformes pour " & VA(i + 1, 1): Exit Sub
            Next
     
    On Error Resume Next ' --------------------------------------------------------------------------------------------------------------
            For i = 1 To (DL - 1) * 2
                Coll_PK.Add Application.Small(Tab_Pk, i), CStr(Application.Small(Tab_Pk, i))
                If Err Then Err.Clear Else j = j + 1:    ReDim Preserve TPK(1 To j):    TPK(j) = Coll_PK(CStr(Application.Small(Tab_Pk, i)))
            Next
            Set Coll_PK = Nothing
     
            For i = 2 To UBound(TPK)
                If TPK(i) > TPK(i - 1) Then
                    PK = TPK(i - 1) & " à " & TPK(i)
                    For j = 2 To DL
                        If VA(j, 2) <= TPK(i - 1) And VA(j, 3) >= TPK(i) Then
                            Coll_PK.Add "|" & VA(j, 1) & "|", PK
                            If Not Err Then Err.Clear:      If InStr(Coll_PK(PK), VA(j, 1) & "|") = 0 Then nom = Coll_PK(PK): Coll_PK.Remove PK:        Coll_PK.Add nom & "|" & VA(j, 1) & "|", PK
                        End If
                    Next
                End If
            Next
    On Error GoTo 0 ' -------------------------------------------------------------------------------------------------------------------
     
            If TB_Source.Count = 1 And Not Application.Intersect(TB_Source, .Columns.Item(1)) Is Nothing Then
                    If Application.Match(TB_Source.Value, .Columns.Item(1), 0) > 1 Then X = Application.Match(TB_Source.Value, .Columns.Item(1), 0): i = X Else i = 2
            Else
                i = 2
            End If
             For i = i To IIf(X > 0, X, .Rows.Count)
                j = 1
                For Each PK In Coll_PK
                    Debug.Print Len(PK)
                    j = j + 1
                    If InStr(PK, "|" & VA(i, 1) & "|") > 0 Then
                        ReDim Preserve Res(1 To 10, 1 To UBound(Res, 2) + 1): nom = Replace(Mid("|" & VA(i, 1) & "|" & Replace(PK, "|" & VA(i, 1) & "|", ""), 2, Len(PK) - 2), "||", " | "): L = UBound(Res, 2)
                        Res(1, L) = TPK(j) - TPK(j - 1):    Res(2, L) = TPK(j - 1) & " à " & TPK(j): Res(3, L) = VA(i, 1):    Res(4, L) = Len(nom) - Len(Replace(nom, "|", "")) + 1:  Res(5, L) = nom
                        Res(7, L) = VA(i, 4):       Res(8, L) = Abatt(IIf(Res(4, L) > 2, 2, Res(4, L) - 1)):        Res(9, L) = Res(1, L) * VA(i, 4) * (1 - (Val(Res(8, L)) / 100)):        Som = Som + Res(9, L)
                    End If
                Next
                Res(6, L) = VA(i, 3) - VA(i, 2):        Res(10, L) = Som:       Som = 0
            Next
    Application.ScreenUpdating = False ' -------------------------------------------------------------------------------------------------------------------
            With .Offset(, .Columns.Count + 3).Resize(1, 1)
              .CurrentRegion.Clear
                .Resize(UBound(Res, 2), UBound(Res)) = Application.Transpose(Res)
                With .CurrentRegion
                    .HorizontalAlignment = xlCenter:        .VerticalAlignment = xlCenter:  .Columns.AutoFit
                    New_inter_Coul 2, .Cells, 3
                    .Borders.Value = 1
                End With
            End With
    Application.ScreenUpdating = True ' -------------------------------------------------------------------------------------------------------------------
        End With
    End Sub
    Edit : petit oubli rectifié

  6. #66
    Membre chevronné
    Inscrit en
    Septembre 2007
    Messages
    1 134
    Détails du profil
    Informations forums :
    Inscription : Septembre 2007
    Messages : 1 134
    Points : 1 808
    Points
    1 808
    Par défaut
    Bonjour à tous,
    Citation Envoyé par Klin89 Voir le message
    Je pense avoir fait le tour : anasecu, c'est le top
    @klin89 Bonne utilisation des algorithmes que tu souhaitais et bon voyages en minibus.

  7. #67
    Membre habitué Avatar de Klin89
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    119
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 119
    Points : 178
    Points
    178
    Par défaut
    re RyuAutodidacte

    La solution du post #65#, c'est la cerise sur le gâteau

    Merci RyuAutodidacte

  8. #68
    Expert confirmé
    Homme Profil pro
    PAO
    Inscrit en
    Octobre 2014
    Messages
    2 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : PAO
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Octobre 2014
    Messages : 2 576
    Points : 4 176
    Points
    4 176
    Par défaut
    Hi Klin89,

    Ce que tu as testé, sont les fonctionnalités d’origine de mon code … , à savoir :

    - la sélection du tableau via une ou plusieurs cellules, à n’importe quel endroit (fait anciennement par le Application.InputBox)

    - option 1, dont je pense que tu viens de le découvrir (puisque le Application.InputBox ne marche pas sur Excel 2003 - normalement à partir de la version 2007 c’est ok), permettant d’avoir le résultat sur un élève choisi.

    - option 2 (via anciennement Application.InputBox) : permettant de choisir la destination du résultat à n’importe quel endroit de la feuille ou du classeur (peut-être même d’un autre classeur, mais ça je n’ai pas testé … !! - ????) (non fait ici)

    L’option 1 et 2 peuvent donc se cumuler …!!!

    Application.InputBox permettait une utilisation plus aisée et ergonomique, mais il y a toujours moyen de faire sans

    Merci d’avoir pris bien le temps de tester

    Au plaisir
    Ryu

    Édit : Petit ajout.

+ Répondre à la discussion
Cette discussion est résolue.
Page 4 sur 4 PremièrePremière 1234

Discussions similaires

  1. Calculer la distance parcourue avec GPSSuitDéplacement
    Par Yves13011 dans le forum Windev Mobile
    Réponses: 2
    Dernier message: 19/10/2018, 17h11
  2. Accéléromètre Android Calcul Distance parcourue
    Par amsolit dans le forum Android
    Réponses: 4
    Dernier message: 14/02/2018, 13h44
  3. Calcul de distance entre deux points en WGS84
    Par marieR dans le forum Langage
    Réponses: 5
    Dernier message: 03/08/2006, 17h07
  4. [GEOMETRIE] calcul de distance dans un triangle
    Par gronaze dans le forum Mathématiques
    Réponses: 10
    Dernier message: 29/06/2006, 10h04
  5. Réponses: 15
    Dernier message: 17/06/2006, 11h49

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo