Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub BtnCompleter()
  2. '
  3. ' BtnCompleter Macro
  4. ' Complete une facture
  5. '
  6. '
  7. Dim cellule As Integer
  8.  
  9. Dim valeurRech As Integer
  10.  
  11. Dim quantite As Integer
  12.  
  13. Dim total As Double
  14.  
  15. Dim bol As Boolean
  16.  
  17. Dim quantiteMaxAtteinte As Boolean
  18.  
  19. cellule = 26 'compte
  20.  
  21. bol = IsEmpty(Cells(cellule, 3))
  22.  
  23. While bol = False
  24.  
  25.  
  26. If IsEmpty(Cells(cellule, 3)) = False Then
  27. valeurRech = Cells(cellule, 4) 'Ajuster la valeur a rechercher
  28. End If
  29.  
  30. feuillePiece = Cells(cellule, 3) 'Ajuster dans quel feuille on va chercher
  31.  
  32. 'Description
  33. Cells(cellule, 5).Value = "=VLOOKUP(" & valeurRech & ",'" & feuillePiece & "'!A:E,2)"
  34.  
  35. quantite = Cells(cellule, 2)
  36.  
  37. 'Verifier si la quantité en stock est suffisante
  38. If (quantite > Evaluate("=VLOOKUP(" & valeurRech & ",'" & feuillePiece & "'!A:E,4)")) Then
  39. MsgBox ("La quantité en stock est insuffisante.")
  40. quantiteMaxAtteint = True
  41. End If
  42.  
  43.  
  44.  
  45. If quantiteMaxAtteint = False Then
  46. 'Prix unité si rabais 0%
  47. If ((Cells(20, 4) = "Non") And (Cells(20, 5) = "Non")) Then
  48. Cells(cellule, 9).Value = "=VLOOKUP(" & valeurRech & ",'" & feuillePiece & "'!A:E,5)"
  49. End If
  50.  
  51. 'Prix unité si rabais 5%
  52. If ((Cells(20, 4) = "Oui") And (Cells(20, 5) = "Non")) Then
  53. Cells(cellule, 9).Value = "=SUM(-VLOOKUP(" & valeurRech & ",'" & feuillePiece & "'!A:E,5) * 0.05,VLOOKUP(" & valeurRech & ",'" & feuillePiece & "'!A:E,5))"
  54. End If
  55.  
  56. 'Prix unité si rabais 10%
  57. If ((Cells(20, 4) = "Non") And (Cells(20, 5) = "Oui")) Then
  58. Cells(cellule, 9).Value = "=SUM(-VLOOKUP(" & valeurRech & ",'" & feuillePiece & "'!A:E,5) * 0.1,VLOOKUP(" & valeurRech & ",'" & feuillePiece & "'!A:E,5))"
  59. End If
  60.  
  61. 'Prix unité si rabais 15%
  62. If ((Cells(20, 4) = "Oui") And (Cells(20, 5) = "Oui")) Then
  63. Cells(cellule, 9).Value = "=SUM(-VLOOKUP(" & valeurRech & ",'" & feuillePiece & "'!A:E,5) * 0.15,VLOOKUP(" & valeurRech & ",'" & feuillePiece & "'!A:E,5))"
  64. End If
  65.  
  66. 'Prix total pour un type de piece
  67. Cells(cellule, 10).Value = quantite * Cells(cellule, 9)
  68. End If
  69.  
  70. cellule = cellule + 1 'ajouter compteur de boucle
  71.  
  72. bol = IsEmpty(Cells(cellule, 3)) 'Verifier si la prochaine cellule est vide
  73.  
  74. Wend
  75. Range("J52") = Evaluate("=SUM(J26:J51)")
  76. Range("J53") = Evaluate("=J52*.05")
  77. Range("J54") = Evaluate("=J52*.095")
  78. Range("J55") = Evaluate("=SUM(J54:J52)")
  79.  
  80. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement