Re : Recherche mot feuilles excel
Le problème c'est que je suis au travail et je ne peux pas joindre le fichier excel.
Je vais copier directement le code ici alors.
voici le code contenu dans ma première Useform me permettant de saisir un courrier à travers des ComboBox et des TextBox :
Private Sub Bt_Valider_Click()
Dim no_ligne As Integer
Dim valeur As String
'Selectionne la bonne feuille en fonction de la Date saisie
valeur = Year(CDate(TextBox2.Text))
Sheets(valeur).Activate
no_ligne = Range("A65536").End(xlUp).Row + 1
no_ligne = Range("B65536").End(xlUp).Row + 1
' Vérification des champs vides obligatoires
If ComboBox1 = "" Or ComboBox2 = "" Or ComboBox3 = "" Or ComboBox4 = "" Or TextBox1 = "" Or TextBox3 = "" Then
' Message d'erreur si les champs obligatoires ne sont pas remplis
MsgBox "Erreur : Veuillez remplir tous les champs obligatoires de la fenêtre (qui ne sont pas en gris)"
Else
' Test pour la Date
If Not IsDate(TextBox2) Then
MsgBox "Erreur : Veuillez saisir correctement la Date"
Else
' Test pour le Tableau de bord
If Not IsNumeric(TextBox5) And IsEmpty(TextBox5) Then
MsgBox "Erreur : Tableau de bord"
Else
' Insère dans la feuille dans le cas ou toutes les conditions sont validées
MsgBox "Le Courrier a bien été inséré"
Cells(no_ligne, 1) = ComboBox1.Value
Cells(no_ligne, 2) = ComboBox2.Value
Cells(no_ligne, 3) = ComboBox3.Value
Cells(no_ligne, 4) = ComboBox4.Value
Cells(no_ligne, 5) = TextBox1.Value
Cells(no_ligne, 6) = TextBox2.Value
Cells(no_ligne, 7) = TextBox3.Value
Cells(no_ligne, 8) = ComboBox5.Value
Cells(no_ligne, 9) = TextBox4.Value
Cells(no_ligne, 10) = TextBox5.Value
'Insertion du lien hypertexte
If TextBox6.Value <> "" Then
Cells(no_ligne, 11).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
TextBox6.Value, _
TextToDisplay:=TextBox6.Value
End If
' Les champs sont vidés si tout est bien validé
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox5 = ""
TextBox6 = ""
ComboBox1 = ""
ComboBox2 = ""
ComboBox3 = ""
ComboBox4 = ""
ComboBox5 = ""
End If
End If
End If
End Sub
Private Sub ComboBox1_Change()
End Sub
Private Sub ComboBox2_Change()
End Sub
Private Sub ComboBox3_Change()
End Sub
Private Sub ComboBox4_Change()
End Sub
Private Sub Frame1_Click()
End Sub
Private Sub ComboBox5_Change()
End Sub
Private Sub CommandButton1_Click()
Dim valeur As String
valeur = Year(TextBox2)
Sheets(valeur).Activate
Range("K65536").End(xlUp).Offset(1, 0).Select
Application.Dialogs(xlDialogInsertHyperlink).Show
TextBox6 = ActiveCell.Hyperlinks(1).Address
ActiveCell.Delete
End Sub
Private Sub CommandButton2_Click()
' Bouton "Annuler" qui ferme la fenêtre de saisie si on clique dessus
Unload Me
Exit Sub
End Sub
Private Sub Label1_Click()
End Sub
Private Sub Label11_Click()
End Sub
Private Sub Label13_Click()
End Sub
Private Sub Label2_Click()
End Sub
Private Sub Label3_Click()
End Sub
Private Sub Label4_Click()
End Sub
Private Sub Label5_Click()
End Sub
Private Sub Label6_Click()
End Sub
Private Sub Label7_Click()
End Sub
Private Sub OK_Click()
End Sub
Private Sub Label8_Click()
End Sub
Private Sub TextBox1_Change()
End Sub
Private Sub TextBox2_Change()
Dim valeur As Byte
TextBox1.MaxLength = 10 'nb caractères maxi autorisé dans le textbox
valeur = Len(TextBox1)
If valeur = 2 Or valeur = 5 Then TextBox1 = TextBox1 & "/"
End Sub
Private Sub TextBox4_Change()
End Sub
Private Sub TextBox5_Change()
End Sub
Private Sub TextBox6_Change()
End Sub
Private Sub UserForm_Activate()
End Sub
Private Sub UserForm_Initialize()
'Bon Format de la Date à saisir
TextBox2.Value = Format(Date, "dd/mm/yyyy")
End Sub
Private Sub TextBox3_Change()
End Sub
Private Sub UserForm_Click()
End Sub