XL 2021 Date et heure

Yacine

XLDnaute Occasionnel
Bonjour le Forum, je voudrais extraire dans mon tableau ci-joint toutes les noms dont la date et l'heure sont avant 01/01/2024 à 23:00

Merci par avance
 

Pièces jointes

  • Date&Heure.xlsx
    9.7 KB · Affichages: 11

job75

XLDnaute Barbatruc
Bonjour Yacine, le fil,

Un p'tit coup de VBA :
VB:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cible, tablo, resu(), i&, x As Variant, n&
cible = [C2]
If FilterMode Then ShowAllData 'si la feuille est filtrée
tablo = Range("A3:B" & Cells(Rows.Count, 1).End(xlUp).Row) 'matrice, plus rapide
ReDim resu(1 To UBound(tablo), 1 To 1)
For i = 1 To UBound(tablo)
    x = tablo(i, 2)
    x = Replace(x, "h", ":")
    If IsDate(x) Then x = CDate(x)
    If x < cible Then
        n = n + 1
        resu(n, 1) = tablo(i, 1)
    End If
Next
'---restitution---
Application.EnableEvents = False
[C3].Resize(UBound(resu)) = resu
Application.EnableEvents = True
End Sub
La macro se déclenche quand on modifie ou valide une cellule quelconque.

A+
 

Pièces jointes

  • Date&Heure VBA.xlsm
    17.3 KB · Affichages: 0
Dernière édition:

Yacine

XLDnaute Occasionnel
Bonjour Yacine, le fil,

Un p'tit coup de VBA :
VB:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cible, tablo, resu(), i&, x As Variant, n&
cible = [C2]
tablo = Range("A3:B" & Cells(Rows.Count, 1).End(xlUp).Row) 'matrice, plus rapide
ReDim resu(1 To UBound(tablo), 1 To 1)
For i = 1 To UBound(tablo)
    x = tablo(i, 2)
    x = Replace(x, "h", ":")
    If IsDate(x) Then x = CDate(x)
    If x < cible Then
        n = n + 1
        resu(n, 1) = tablo(i, 1)
    End If
Next
'---restitution---
Application.EnableEvents = False
If FilterMode Then ShowAllData 'si la feuille est filtrée
[C3].Resize(UBound(resu)) = resu
Application.EnableEvents = True
End Sub
La macro se déclenche quand on modifie ou valide une cellule quelconque.

A+
Cooooool merci beaucoup
 

Discussions similaires

Réponses
46
Affichages
871