Autres (RESOLU)Textbox dans une feuille pour recherche format Date

chaelie2015

XLDnaute Accro
Bonjour Forum
je souhaite ajouter a la Textbox1 dans la feuille une exigence ( textbox01) format date jjjj jj/mm/aaaa lors de la saisie.
VB:
Private Sub TextBox1_Change() 'Recherche date
    
    Application.ScreenUpdating = False
    
    Range("c2:c365").Interior.ColorIndex = 2
    
    
    If TextBox1 <> "" Then
        For ligne = 2 To 365
            If Cells(ligne, Range("date").Column) Like "*" & TextBox1 & "*" Then
                Cells(ligne, Range("date").Column).Interior.ColorIndex = 37
                
            End If
        Next
    End If
    
    
End Sub

Merci
 

Pièces jointes

  • Charlie textbox date.xlsm
    21.6 KB · Affichages: 6
Solution
Re

A tester
VB:
Private Sub Textbox1_Change()
Dim rng As Range
Select Case Len(TextBox1)
Case Is = 10
If IsDate(TextBox1) Then
Set rng = Columns(1).Cells.Find(CDate(Me.TextBox1.Value), LookIn:=xlValues)
If Not rng Is Nothing Then
rng.Interior.ColorIndex = 37
Application.Goto rng, True
End If
End If
Case Else
Range("A:A").Interior.ColorIndex = 2
End Select
End Sub
NB: ici l'exemple est toujours basée sur la colonne A

chaelie2015

XLDnaute Accro
Re
je souhaite ajouter a ce code de recherche ce qui suit :
si je saisi la date complète dans le textbox1 aller vers la ligne qui la corresponde.
exemple : je saisi par exemple dans textbox : 23/09/2022 aller vers la ligne 156.
merci FORUM
 

Pièces jointes

  • Charlie textbox date.xlsm
    23.9 KB · Affichages: 4

Staple1600

XLDnaute Barbatruc
RE

A tester et adapter
(ici lors de mon test, les valeurs étaient en colonne A)
VB:
Private Sub Textbox1_Change()
Dim rng As Range
If Len(TextBox1) = 10 Then
If IsDate(TextBox1) Then
Set rng = Columns(1).Cells.Find(CDate(Me.TextBox1.Value), LookIn:=xlValues)
If Not rng Is Nothing Then
Application.Goto rng, True
Else
Exit Sub
End If
End If
End If
End Sub
 

Staple1600

XLDnaute Barbatruc
Re

A tester et adapter
VB:
Private Sub Textbox1_Change()
Dim rng As Range
If Len(TextBox1) = 10 Then
If IsDate(TextBox1) Then
Set rng = Columns(1).Cells.Find(CDate(Me.TextBox1.Value), LookIn:=xlValues)
If Not rng Is Nothing Then
rng.Interior.ColorIndex = 37
Application.Goto rng, True
Else
Exit Sub
End If
End If
End If
End Sub
 

chaelie2015

XLDnaute Accro
Re

Dans ton code exemple (celui du message#1)
Le ColorIndex était à 37
Donc j'ai repris 37
Re
oui c'est ca , mais je souhaite une fois je vide la textbox la cellule revient a sa couleur blanche.
comme jai mentionné dans mon message 1
Range("c2:c365").Interior.ColorIndex = 2

VB:
Private Sub Textbox1_Change()
Dim rng As Range

Range("c2:c365").Interior.ColorIndex = 2
If Len(TextBox1) = 10 Then
If IsDate(TextBox1) Then
Set rng = Columns(1).Cells.Find(CDate(Me.TextBox1.Value), LookIn:=xlValues)
If Not rng Is Nothing Then
rng.Interior.ColorIndex = 37
Application.Goto rng, True
Else
Exit Sub
End If
End If
End If
End Sub

c'est bon maintenant ça fonctionne , merci

a+
 

Staple1600

XLDnaute Barbatruc
Re

A tester
VB:
Private Sub Textbox1_Change()
Dim rng As Range
Select Case Len(TextBox1)
Case Is = 10
If IsDate(TextBox1) Then
Set rng = Columns(1).Cells.Find(CDate(Me.TextBox1.Value), LookIn:=xlValues)
If Not rng Is Nothing Then
rng.Interior.ColorIndex = 37
Application.Goto rng, True
End If
End If
Case Else
Range("A:A").Interior.ColorIndex = 2
End Select
End Sub
NB: ici l'exemple est toujours basée sur la colonne A
 

Discussions similaires

Statistiques des forums

Discussions
311 725
Messages
2 081 943
Membres
101 849
dernier inscrit
florentMIG