Mehdi8822 b
XLDnaute Nouveau
Bonjour,
comment cree les duex code de "Private Sub Worksheet_Change "sur même feuille
Voici ci-dessous un code VB qui me permet :affiche la date si un cellie non vide de 5a24: (si D<>""donc C= affiche la date )et( si L<>""donc K= affiche la date) sont mise a jours:
le code (1) est fonctionne correctement
le code (2) n'est pas fonctionne
code(1):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim h, iSct As Range
Set iSct = Intersect(Target, Range("C5:C24"))
If iSct Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each h In iSct.Cells
If IsEmpty(h) Then
h.Offset(0, 1) = ""
Else
h.Offset(0, 1) = Format(Now, "mm/dd/yy")
End If
Next
Application.EnableEvents = True
End Sub
code(2):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim h, j, iSct As Range
Set iSct = Intersect(Target, Range("C5:C24"))
Set iSct = Intersect(Target, Range("K5:K24"))
If iSct Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each h In iSct.Cells
If IsEmpty(h) Then
h.Offset(0, 1) = ""
Else
h.Offset(0, 1) = Format(Now, "mm/dd/yy")
End If
If iSct Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each j In iSct.Cells
If IsEmpty(j) Then
j.Offset(0, 1) = ""
Else
j.Offset(0, 1) = Format(Now, "mm/dd/yy")
End If
Next
Application.EnableEvents = True
End Sub
Par exemmple taper une valeur en C5 pour D=18/08/2019.
Comment puis-je procéder s'il vous plait ?
Merci par avance.
comment cree les duex code de "Private Sub Worksheet_Change "sur même feuille
Voici ci-dessous un code VB qui me permet :affiche la date si un cellie non vide de 5a24: (si D<>""donc C= affiche la date )et( si L<>""donc K= affiche la date) sont mise a jours:
le code (1) est fonctionne correctement
le code (2) n'est pas fonctionne
code(1):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim h, iSct As Range
Set iSct = Intersect(Target, Range("C5:C24"))
If iSct Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each h In iSct.Cells
If IsEmpty(h) Then
h.Offset(0, 1) = ""
Else
h.Offset(0, 1) = Format(Now, "mm/dd/yy")
End If
Next
Application.EnableEvents = True
End Sub
code(2):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim h, j, iSct As Range
Set iSct = Intersect(Target, Range("C5:C24"))
Set iSct = Intersect(Target, Range("K5:K24"))
If iSct Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each h In iSct.Cells
If IsEmpty(h) Then
h.Offset(0, 1) = ""
Else
h.Offset(0, 1) = Format(Now, "mm/dd/yy")
End If
If iSct Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each j In iSct.Cells
If IsEmpty(j) Then
j.Offset(0, 1) = ""
Else
j.Offset(0, 1) = Format(Now, "mm/dd/yy")
End If
Next
Application.EnableEvents = True
End Sub
Par exemmple taper une valeur en C5 pour D=18/08/2019.
Comment puis-je procéder s'il vous plait ?
Merci par avance.