XL 2016 Uniformiser la date des cellules

Phylo

XLDnaute Occasionnel
Bonjour

J 'ai crée un fichier excel qvec un code vba qui incorpore la date automatiquement
Mais vu que le fichier est utilisé par plusieurs personne. La date entrée est variable selon la date d' ordi de chaque personne

je veux insérer l'instruction dans ce code

Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Not Intersect(Target, Columns("J")) Is Nothing And Target.Value <> "" Then
Target.Offset(0, 1).Value = Date & " " & Time
End If

'Dans les colonnes I et K la format de la date est : dd-mm-yyyy
exemple :
Columns()Numberformat="dd-mm-yyyy"


Merci d'avance
 

Pièces jointes

  • FOR-AQ release inbox 07-09-2020.xlsm
    765.1 KB · Affichages: 107
Solution
Mode:=1 est à préciser après une virgule à la fin d'une instruction CA.Add dans la Sub UserForm_Initialize.
Oui, elle ne gène pas, elle est là au cas où vous auriez besoin un jour de pouvoir en supprimer une. Ne serait-ce qu'à la suite d'un ajout avec une information erronée tapée dans une ComboBox.

Je joint mon classeur où j'ai déplacé un ou deux CA.Add pour qu'ils soient dans un ordre plus proche de celui des colonnes du tableau.

Phylo

XLDnaute Occasionnel
le code n'a pas encore marché

j'ai changé la configuration a tous le monde mais malgré ça

1600109627377.png
 

Dranreb

XLDnaute Barbatruc
Joignez le classeur.
Normalement ça devrait marcher.
Et vous n'avez pas mis les Application.EnableEvents = False puis True ?
À chaque fois que vous mettez cette date ça la ré-exécute. Est-ce que ça ne le contrecarre pas ?
Normalement non si vous avez bien indiqué toute la procédure. Mais c'est un principe: ne jamais changer de cellule dans une Sub WorkSheet_Change sans avoir préalablement exécuté Application.EnableEvents = False. C'est un coup à saturer la pile des appels.
 
Dernière édition:

Dranreb

XLDnaute Barbatruc
Ce n'est pas tout à fait la même chose.
J'ai eu la surprise de le voir interpréter Now alors que c'était déjà une date et une heure.
J'ai dû utiliser Value2 pour l'obliger à prendre ce que je lui mets, un point c'est tout !
Ça se rapproche là ? :
VB:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Intersect(Me.ListObjects(1).DataBodyRange, Target) Is Nothing Then Exit Sub
   If Not Intersect([J:J,L:L,N:N,S:S,U:U,W:W], Target) Is Nothing Then
      Application.EnableEvents = False
      With Target.Offset(0, 1)
         .NumberFormat = "m/d/yyyy h:mm": .Value2 = Now: End With
      If Not Intersect([J:J,S:S], Target) Is Nothing Then
         With Target.Offset(0, -1)
            .NumberFormat = "m/d/yyyy h:mm": .Value2 = Now + 2: End With
         End If
      Application.EnableEvents = True
   ElseIf Target.Column = 2 Then
      Dim Cel As Range
      Set Cel = Sheets("Mes listes").Columns(1).Cells.Find(what:=Target.Value, LookAt:=xlWhole)
      If Not Cel Is Nothing Then
         Application.EnableEvents = False
         Target.Offset(0, 1).Value = Cel.Offset(0, 1).Value
         Application.EnableEvents = True
         End If
      End If
   End Sub
 

Phylo

XLDnaute Occasionnel
Je veux pas d'indépendance des colonnes
si je rempli par exemple J et il remplie K et M

je veux comme c'était séparé
j'ai essayé ce code mais ne marche pas


VB:
 Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Intersect(Me.ListObjects(1).DataBodyRange, Target) Is Nothing Then Exit Sub
   If Not Intersect([J:J], Target) Is Nothing Then
      Application.EnableEvents = False
      With Target.Offset(0, 1)
         .NumberFormat = "m/d/yyyy": .Value2 = Date: End With
  If Not Intersect([L:L], Target) Is Nothing Then
      Application.EnableEvents = False
      With Target.Offset(0, 1)
         .NumberFormat = "m/d/yyyy": .Value2 = Date: End With
 If Not Intersect([N:N], Target) Is Nothing Then
      Application.EnableEvents = False
      With Target.Offset(0, 1)
         .NumberFormat = "m/d/yyyy": .Value2 = Date: End With

 If Not Intersect([S:S], Target) Is Nothing Then
      Application.EnableEvents = False
      With Target.Offset(0, 1)
         .NumberFormat = "m/d/yyyy": .Value2 = Date: End With
 If Not Intersect([U:U], Target) Is Nothing Then
      Application.EnableEvents = False
      With Target.Offset(0, 1)
         .NumberFormat = "m/d/yyyy": .Value2 = Date: End With
If Not Intersect([W:W], Target) Is Nothing Then
      Application.EnableEvents = False
      With Target.Offset(0, 1)
         .NumberFormat = "m/d/yyyy": .Value2 = Date: End With
If Not Intersect([J:J], Target) Is Nothing Then
         With Target.Offset(0, -1)
            .NumberFormat = "m/d/yyyy": .Value2 = Date + 2: End With
If Not Intersect([S:S], Target) Is Nothing Then
         With Target.Offset(0, -1)
            .NumberFormat = "m/d/yyyy": .Value2 = Date + 2: End With
      Application.EnableEvents = True
   ElseIf Target.Column = 2 Then
      Dim Cel As Range
      Set Cel = Sheets("Mes listes").Columns(1).Cells.Find(what:=Target.Value, LookAt:=xlWhole)
      If Not Cel Is Nothing Then
         Application.EnableEvents = False
         Target.Offset(0, 1).Value = Cel.Offset(0, 1).Value
         Application.EnableEvents = True
         End If
   End Sub
 

Dranreb

XLDnaute Barbatruc
Voulez-vous dire que ça doit réagir si on modifie plusieurs cellules en même temps ?
Je n'ai pas l'impression.
Le code que je proposai au #20 prévoyait bien un traitement supplémentaire des cellules à gauche des colonnes J et S, en plus de celui de celles à leur droite.
Je ne comprends pas ce que vous voulez dire.
Dans votre code il me semble y avoir un risque que Application.EnableEvents soit laissé à False à la fin de l'exécution. Après plus rien ne marche !
Et puis écrit comme ça il doit manquer plein de End If, non ?
 

Phylo

XLDnaute Occasionnel
Salut

J'ai constaté comme si j'ai une fonction now malgré que j'ai mis date a la place ???
moi je veux qu'il me fige la date enregistré mais avec une format dd-mm-aaaa
tout est fonctionnel

VB:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Intersect(Me.ListObjects(1).DataBodyRange, Target) Is Nothing Then Exit Sub
   If Not Intersect([J:J,L:L,N:N,S:S,U:U,W:W], Target) Is Nothing Then
      Application.EnableEvents = False
      With Target.Offset(0, 1)
         .NumberFormat = "m/d/yyyy": .Value2 = Date: End With
      If Not Intersect([J:J,S:S], Target) Is Nothing Then
         With Target.Offset(0, -1)
            .NumberFormat = "m/d/yyyy": .Value2 = Date + 2: End With
         End If
      Application.EnableEvents = True
   ElseIf Target.Column = 2 Then
      Dim Cel As Range
      Set Cel = Sheets("Mes listes").Columns(1).Cells.Find(what:=Target.Value, LookAt:=xlWhole)
      If Not Cel Is Nothing Then
         Application.EnableEvents = False
         Target.Offset(0, 1).Value = Cel.Offset(0, 1).Value
         Application.EnableEvents = True
         End If
      End If
   End Sub
 

Discussions similaires

Statistiques des forums

Discussions
312 177
Messages
2 085 972
Membres
103 073
dernier inscrit
MSCHOE16