Bonjour le Forum,
J’ai une superbe procédure de recherche, mais j'aimerai gérer au maximum les erreurs, donc :
Dans cette procédure, je fais une recherche sur une colonne complète, les variable pour effectuer cette recherche provienne d'un InputBox et le problème est que si l'utilisateur introduit un mauvais format (ex : 01/15/2003 ou blablabla) il y a une erreur donc j'aimerai tester le format de la variable avant de commencer la recherche et je ne connais pas la syntaxe pour tester un format
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 Private Sub rech() Dim i As Integer, Datedeb As Date, Datefin As Date Dim graph As Chart Application.ScreenUpdating = False If Sheets("Index").OptionButton10.Value = True Then Datedeb = Sheets("Index").TextBox1 Datefin = Sheets("Index").TextBox2 End If If Sheets("Index").OptionButton7.Value = True Then Datedeb = Date - 388 Datefin = Date - 30 End If du = Date au = Date 'tester si les dates sont dans un format correct 'If Datedeb OR Datefin <> DATE.Format Then 'MsgBox "Les dates doivent être dans un format JJ/MM/AAAA" 'Exit Sub 'End If If Datedeb >= Datefin Then MsgBox "la date de fin doit être postérieure à la date de début" Exit Sub End If With Sheets("Données") For i = 4 To .Cells(Rows.Count, 1).End(xlUp).Row If .Cells(i, 2) = Datedeb Then Ligdeb = i du = .Cells(i, 2) Exit For ElseIf .Cells(i, 2) > Datedeb Then Ligdeb = i - 1 du = .Cells(i - 1, 2) Exit For End If Next For i = 4 To .Cells(Rows.Count, 1).End(xlUp).Row If .Cells(i, 2) = Datefin Then LigFin = i au = .Cells(i, 2) Exit For ElseIf .Cells(i, 2) > Datefin Then LigFin = i - 1 au = .Cells(i - 1, 2) Exit For End If Next End With End Sub
Partager