Fonction VBA avec incrémentation

Bonjour,

Voilà mon petit projet :

J'ai mis en place un excel avec des inputbox qui sont retransmises dans des tableau sur d'autres feuilles. Jusque là, tout fonctionne.

Par contre, j'aimerais faire en sorte que dès qu'une nouvelle saisie est faite, lorsqu'il reprends les elements saisi, il passe à la cellule suivante qui est vide. Pour le moment, il ecrase la/les même cellules constemment.

Voici le code actuel :

Sub SortieStock()

Dim d1, d2, d3, d4

d1 = InputBox("Numéro d'incident :")
d2 = InputBox("NIV du produit :")
d3 = InputBox("Votre trigramme :")
d4 = InputBox("Commentaire:")

Sheets("Sortie_de_stock").Range("B3") = d1
Sheets("Sortie_de_stock").Range("E3") = d2
Sheets("Sortie_de_stock").Range("G3") = d3
Sheets("Sortie_de_stock").Range("I3") = d4

End Sub

Sub Entréestock()

Dim d1, d2, d3, d4, d5

d1 = InputBox("Numéro d'incident :")
d2 = InputBox("NIV du produit :")
d3 = InputBox("Etat de stock : ")
d4 = InputBox("Votre trigramme :")
d5 = InputBox("Commentaire:")

Sheets("Entrée_de_stock").Range("B3").End(xlDown) = d1
Sheets("Entrée_de_stock").Range("E3").End(xlDown) = d2
Sheets("Entrée_de_stock").Range("G3").End(xlDown) = d3
Sheets("Entrée_de_stock").Range("I3").End(xlDown) = d4
Sheets("Entrée_de_stock").Range("K3").End(xlDown) = d5

End Sub

Merci de votre précieuse aide

Bonjour

Une solution

Sub SortieStock()
Dim Ligne As Long
Dim d1, d2, d3, d4

  d1 = InputBox("Numéro d'incident :")
  d2 = InputBox("NIV du produit :")
  d3 = InputBox("Votre trigramme :")
  d4 = InputBox("Commentaire:")

  With Sheets("Sortie_de_stock")
    Ligne = .Range("B" & Rows.Count).End(xlUp).Row + 1
    .Range("B" & Ligne) = d1
    .Range("E" & Ligne) = d2
    .Range("G" & Ligne) = d3
    .Range("I" & Ligne) = d4
  End With
End Sub

Sub Entréestock()
Dim d1, d2, d3, d4, d5
Dim Ligne As Long

  d1 = InputBox("Numéro d'incident :")
  d2 = InputBox("NIV du produit :")
  d3 = InputBox("Etat de stock : ")
  d4 = InputBox("Votre trigramme :")
  d5 = InputBox("Commentaire:")

  With Sheets("Entrée_de_stock")
    Ligne = .Range("B" & Rows.Count).End(xlUp).Row + 1
    .Range("B" & Ligne) = d1
    .Range("E" & Ligne) = d2
    .Range("G" & Ligne) = d3
    .Range("I" & Ligne) = d4
    .Range("K" & Ligne) = d4
  End With

End Sub

C'est exactement ce qu'il me fallait !

Merci !!

Je reviens encore une fois vers vous :

Est-il possible d'implémenter une colonne, ou à chaque nouvelle saisie dans une ligne, il rajoute la date+heure du jour dans une cellule à coté ?

j'ai tenté mais en vain.

Voici l'état actuel de mon code :

Sub Sortiestock()
Dim Ligne As Long
Dim d1, d2, d3, d4, d5

Worksheets("Sortie_de_stock").Unprotect Password:="******"

  d1 = InputBox("Numéro d'incident :")
  d2 = InputBox("NIV + NS + Designation du produit :")
  d3 = InputBox("Votre trigramme :")
  d4 = InputBox("Heures et minutes (HH:MM) :")
  d5 = InputBox("Commentaire :")

  With Sheets("Sortie_de_stock")
    Ligne = .Range("B" & Rows.Count).End(xlUp).Row + 1
    .Range("B" & Ligne) = d1
    .Range("E" & Ligne) = d2
    .Range("G" & Ligne) = d3
    .Range("H" & Ligne) = d4
    .Range("I" & Ligne) = d5

  End With

Worksheets("Sortie_de_stock").Protect Password:="******"

End Sub

Sub Entréestock()
Dim d1, d2, d3, d4, d5, d6
Dim Ligne As Long

Worksheets("Entrée_de_stock").Unprotect Password:="******"

  d1 = InputBox("Numéro d'incident :")
  d2 = InputBox("NIV + NS + Designation du produit :")
  d3 = InputBox("Etat de stock : (Spare, Réparation, Neuf, Rebut) ")
  d4 = InputBox("Votre trigramme :")
  d5 = InputBox("Heures et mintues : (Format HH:MM)")
  d6 = InputBox("Commentaire :")

  With Sheets("Entrée_de_stock")
    Ligne = .Range("B" & Rows.Count).End(xlUp).Row + 1
    .Range("B" & Ligne) = d1
    .Range("E" & Ligne) = d2
    .Range("G" & Ligne) = d3
    .Range("I" & Ligne) = d4
    .Range("J" & Ligne) = d5
    .Range("K" & Ligne) = d6

  End With
Worksheets("Entrée_de_stock").Protect Password:="******"

End Sub

Par avance, merci !

Bonjour

A tester

Sub Sortiestock()
Dim Ligne As Long
Dim d1, d2, d3, d4, d5

Worksheets("Sortie_de_stock").Unprotect Password:="******"

  d1 = InputBox("Numéro d'incident :")
  d2 = InputBox("NIV + NS + Designation du produit :")
  d3 = InputBox("Votre trigramme :")
  'd4 = InputBox("Heures et minutes (HH:MM) :")
  d5 = InputBox("Commentaire :")

  With Sheets("Sortie_de_stock")
    Ligne = .Range("B" & Rows.Count).End(xlUp).Row + 1
    .Range("B" & Ligne) = d1
    .Range("E" & Ligne) = d2
    .Range("G" & Ligne) = d3
    .Range("H" & Ligne) = Now
    .Range("I" & Ligne) = d5

  End With

Worksheets("Sortie_de_stock").Protect Password:="******"

End Sub
Sub Entréestock()
Dim d1, d2, d3, d4, d5, d6
Dim Ligne As Long

Worksheets("Entrée_de_stock").Unprotect Password:="220890"

  d1 = InputBox("Numéro d'incident :")
  d2 = InputBox("NIV + NS + Designation du produit :")
  d3 = InputBox("Etat de stock : (Spare, Réparation, Neuf, Rebut) ")
  d4 = InputBox("Votre trigramme :")
  'd5 = InputBox("Heures et mintues : (Format HH:MM)")
  d6 = InputBox("Commentaire :")

  With Sheets("Entrée_de_stock")
    Ligne = .Range("B" & Rows.Count).End(xlUp).Row + 1
    .Range("B" & Ligne) = d1
    .Range("E" & Ligne) = d2
    .Range("G" & Ligne) = d3
    .Range("I" & Ligne) = d4
    .Range("J" & Ligne) = Now
    .Range("K" & Ligne) = d6
  End With
Worksheets("Entrée_de_stock").Protect Password:="220890"

End Sub

C'est tout à fait ça. Milles merci, mon excel est au point !

Rechercher des sujets similaires à "fonction vba incrementation"