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

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

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

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
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
 
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
 
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+
 
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
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Retour