Bobbyjack
Messages postés5Date d'inscriptionjeudi 28 juin 2012StatutMembreDernière intervention30 juin 2012
-
29 juin 2012 à 23:44
Bobbyjack
Messages postés5Date d'inscriptionjeudi 28 juin 2012StatutMembreDernière intervention30 juin 2012
-
30 juin 2012 à 00:28
Bonsoir,
J'ai écris un code qui doit entres autres remplir à chaque fois la ligne suivante avec les informations qu'on donne via un useform.
Mon code marche en exécutant le code directement via VisualBasic, il fonctionne également lorsque le bouton qui fait apparaître le userform se trouve sur la même feuille que le tableau qui doit se remplir avec les données MAIS mon code ne fonctionne pas lorsque le bouton se trouve sur une autre feuille (ce que je veux) et je ne comprends pas pourquoi.
Voici mon code :
Private Sub UFormDesac_Valider_Click()
'Cherche le numero de la dernière ligne remplie
Dim LastRow As Integer
LastRow = Cells.Find("*", , , , , xlPrevious).Row
'Contrôles
'Contrôle Nom
If Me.UFormDesac_TextBoxNom = "" Then
MsgBox "Saisir un nom!"
Me.UFormDesac_TextBoxNom.SetFocus
Exit Sub
End If
If IsNumeric(UFormDesac_TextBoxNom) Then
MsgBox "Nom incorrecte!", vbCritical, "ATTENTION !"
UFormDesac_TextBoxNom = ""
UFormDesac_TextBoxNom.SetFocus
Exit Sub
End If
With Sheets("AJOUT_DESAC").Range("A:A")
Dim c As Range
Set c = .Find(UFormDesac_TextBoxNom.Value, LookIn:=xlValues)
If Not c Is Nothing Then
MsgBox "Nom déja existant!"
UFormDesac_TextBoxNom.SetFocus
Exit Sub
End If
End With
'Contrôle NDC
If Me.UFormDesac_TextBoxNDC = "" Then
MsgBox "Saisir NDC!"
Me.UFormDesac_TextBoxNDC.SetFocus
Exit Sub
End If
With Sheets("AJOUT_DESAC").Range("B:B")
Dim b As Range
Set b = .Find(Me.UFormDesac_TextBoxNDC.Value, LookIn:=xlValues)
If Not b Is Nothing Then
MsgBox "NDC déja existant!"
UFormDesac_TextBoxNom.SetFocus
Exit Sub
End If
End With
'Contrôle Nature de la désactivation
If Me.UFormDesac_NatureDesac = "" Then
MsgBox "Choisir type de désactivation!"
Me.UFormDesac_NatureDesac.SetFocus
Exit Sub
End If
Select Case Me.UFormDesac_NatureDesac
Case Is = ["Non évitable"]
Case Is = ["Evitable"]
Case Else
MsgBox "Type de désactivation invalide!"
Me.UFormDesac_NatureDesac.SetFocus
Exit Sub
End Select
'Cherche le numero de la dernière ligne remplie
Dim LastRow As Integer
LastRow = Cells.Find("*", , , , , xlPrevious).Row
With Sheets("AJOUT_DESAC")
With .Range("A" & LastRow + 1)
.Value = Me.UFormDesac_TextBoxNom
.Borders(xlEdgeLeft).Weight = xlThick
.Borders(xlEdgeRight).Weight = xlMedium
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeBottom).Weight = xlThick
End With
With .Range("B" & LastRow + 1)
.Value = Me.UFormDesac_TextBoxNDC
.Borders(xlEdgeRight).Weight = xlMedium
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeBottom).Weight = xlThick
End With
With .Range("C" & LastRow + 1)
.Value = Me.UFormDesac_TextBoxDateEntree
.Borders(xlEdgeRight).Weight = xlMedium
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeBottom).Weight = xlThick
End With
With .Range("D" & LastRow + 1)
.Value = Me.UFormDesac_NatureDesac
.Borders(xlEdgeRight).Weight = xlMedium
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeBottom).Weight = xlThick
End With
With .Range("E" & LastRow + 1)
.Value = Me.UFormDesac_TextBoxCommentaire
.Borders(xlEdgeRight).Weight = xlThick
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeBottom).Weight = xlThick
'permet l'ajustement en hauteur de la cellule qui va contenir le commentaire
.WrapText = True
End With
'permet de supprimer les lignes vides (si une personne a supprimé directement dans le tableau)
.Range("A1:A200").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End With
Unload Me
End Sub