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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| Dim I As Integer, J As Integer, K As Integer, L As Integer, M As Integer 'Variables de boucles
Dim x As Integer, y As Integer, W As Integer 'Variables comparatives
Dim Tableau1() As String, Tableau2() As String 'Variables tableaux
Dim Z As String 'Variable simplificatrice
'Demander si fusion ou non des lignes similaires : Si oui attention perte de données des dimensions non utilisées par la formule
Rep2 = MsgBox("Souhaitez vous fusionner les ouvrages de même typologie ?" & vbLf & _
"Attention perte de données des dimensions non utilisées par la formule", vbYesNo, "Fusion des données")
'Boucle sur feuille
For I = 7 To Sheets.Count
'Fusion des lignes similaires sur réponse oui au msgbox
If Rep2 = vbYes Then
Z = " / "
x = Sheets(I).Range("A65000").End(xlUp).Row
For K = x To 3 Step -1 'Boucle sur ligne feuille
'Vérification si K et K-1 sont identiques
If Sheets(I).Cells(K, 1) = Sheets(I).Cells(K - 1, 1) _
And Sheets(I).Cells(K, 2) = Sheets(I).Cells(K - 1, 2) _
And Sheets(I).Cells(K, 3) = Sheets(I).Cells(K - 1, 3) _
And Sheets(I).Cells(K, 4) = Sheets(I).Cells(K - 1, 4) _
And Sheets(I).Cells(K, 5) = Sheets(I).Cells(K - 1, 5) _
And Sheets(I).Cells(K, 6) = Sheets(I).Cells(K - 1, 6) _
And Sheets(I).Cells(K, 7) = Sheets(I).Cells(K - 1, 7) _
And Sheets(I).Cells(K, 9) = Sheets(I).Cells(K - 1, 9) _
And Sheets(I).Cells(K, 10) = Sheets(I).Cells(K - 1, 10) _
And Sheets(I).Cells(K, 16) = Sheets(I).Cells(K - 1, 16) Then
'Concaténation colonne dimensions
'Découpe la chaine en fonction des " / " (Z) : Le résultat de la fonction Split est stocké dans un tableau
Tableau1 = Split(Sheets(I).Cells(K, 8), Z)
Tableau2 = Split(Sheets(I).Cells(K - 1, 8), Z)
Select Case Sheets(I).Cells(K, 16)
Case "d*Qte", "m*Qte"
'Scinder les dimensions pour ne prendre que Qte sur ligne K
For L = 0 To UBound(Tableau1)
If InStr(Tableau1(L), "Q") Then
Tableau1(L) = Replace(Tableau1(L), ",", ".")
Tableau1(L) = Replace(Tableau1(L), " ", "x")
For M = 1 To Len(Tableau1(L))
If IsNumeric(Mid(Tableau1(L), M, 1)) Then
Sheets(I).Cells(K, 8) = Val(Mid(Tableau1(L), M, Len(Tableau1(L)) - M + 1))
End If
Next M
End If
Next L
'Scinder les dimensions pour ne prendre que Qte sur ligne K-1
For L = 0 To UBound(Tableau2)
If InStr(Tableau2(L), "Q") Then
Tableau2(L) = Replace(Tableau2(L), ",", ".")
Tableau2(L) = Replace(Tableau2(L), " ", "x")
For M = 1 To Len(Tableau2(L))
If IsNumeric(Mid(Tableau2(L), M, 1)) Then
Sheets(I).Cells(K - 1, 8) = Val(Mid(Tableau2(L), M, Len(Tableau2(L)) - M + 1))
End If
Next M
End If
Next L
'Associer la valeur K + K-1 que ligne K-1
Sheets(I).Cells(K - 1, 8) = Val(Sheets(I).Cells(K, 8)) + Val(Sheets(I).Cells(K - 1, 8))
Sheets(I).Cells(K - 1, 8).NumberFormat = "#,##0"
Sheets(I).Cells(K - 1, 8) = "Qte " & Sheets(I).Cells(K - 1, 8) & "u"
Case "L*d"
For L = 0 To UBound(Tableau1)
If InStr(Tableau1(L), "L") Then
Tableau1(L) = Replace(Tableau1(L), ",", ".")
Tableau1(L) = Replace(Tableau1(L), " ", "x")
For M = 1 To Len(Tableau1(L))
If IsNumeric(Mid(Tableau1(L), M, 1)) Then
Sheets(I).Cells(K, 8) = Val(Mid(Tableau1(L), M, Len(Tableau1(L)) - M + 1))
End If
Next M
End If
Next L
For L = 0 To UBound(Tableau2)
If InStr(Tableau2(L), "L") Then
Tableau2(L) = Replace(Tableau2(L), ",", ".")
Tableau2(L) = Replace(Tableau2(L), " ", "x")
For M = 1 To Len(Tableau2(L))
If IsNumeric(Mid(Tableau2(L), M, 1)) Then
Sheets(I).Cells(K - 1, 8) = Val(Mid(Tableau2(L), M, Len(Tableau2(L)) - M + 1))
End If
Next M
End If
Next L
Sheets(I).Cells(K - 1, 8) = Val(Sheets(I).Cells(K, 8)) + Val(Sheets(I).Cells(K - 1, 8))
Sheets(I).Cells(K - 1, 8).NumberFormat = "#,##0.0"
Sheets(I).Cells(K - 1, 8) = "L " & Sheets(I).Cells(K - 1, 8) & "m"
End Select
Sheets(I).Cells(K - 1, 11) = Val(Replace(Sheets(I).Cells(K, 11), ",", ".")) + Val(Replace(Sheets(I).Cells(K - 1, 11), ",", ".")) 'Poids total
Sheets(I).Cells(K - 1, 11).NumberFormat = "0.000\ t"
Sheets(I).Cells(K - 1, 10).NumberFormat = "0"
'Concaténation colonne remarques
W = 0
If Sheets(I).Cells(K, 12) <> "" Then
Tableau1 = Split(Sheets(I).Cells(K, 12), Z)
'Boucle sur le tableau pour tester le résultat
For L = 0 To UBound(Tableau1)
If Tableau1(L) = Sheets(I).Cells(K - 1, 12) Then W = 1
Next L
If W = 0 And Sheets(I).Cells(K - 1, 12) <> "" Then Sheets(I).Cells(K - 1, 12) = Sheets(I).Cells(K, 12) & Z & Sheets(I).Cells(K - 1, 12)
End If
'Concaténation colonne localisation
W = 0
If Sheets(I).Cells(K, 12) <> "" Then
Tableau1 = Split(Sheets(I).Cells(K, 13), Z)
'Boucle sur le tableau pour tester le résultat
For L = 0 To UBound(Tableau1)
If Tableau1(L) = Sheets(I).Cells(K - 1, 13) Then W = 1
Next L
If W = 0 And Sheets(I).Cells(K - 1, 13) <> "" Then Sheets(I).Cells(K - 1, 13) = Sheets(I).Cells(K - 1, 13) & Z & Sheets(I).Cells(K, 13)
End If
'Concaténation colonne ID Saisie
Sheets(I).Cells(K - 1, 15) = Sheets(I).Cells(K - 1, 15) & "/" & Sheets(I).Cells(K, 15)
'Suppression de la ligne K si identique à K-1, après concaténation des données sur K-1
Rows(K & ":" & K).Delete 'Shift:=xlUp
End If
Next K
End If
Next I |
Partager