créer sa propre liste en vba avec validation de données
Bonjour le forum,
J'ajoute sur une feuille excel protégée, une ligne en lui paramétrant les données d'utilisateur.
Code:
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| Sub saisuiv(modif As Boolean)
Sheets("SUIVI").Unprotect
Load formSaisi
If modif = True Then
lig = ActiveCell.Row
tit = Sheets("SUIVI").Range("d" & lig).Value
For lig1 = 0 To formSaisi.lisAge.ListCount - 1
If tit = formSaisi.lisAge.List(lig, 0) Then
formSaisi.lisAge.ListIndex = lig1
Exit For
End If
Next
Else
lig = 15
Do While Sheets("SUIVI").Range("c" & lig).Value <> ""
lig = lig + 1
If lig = 10000 Then
MsgBox "erreur systeme, contacter le concepteur", vbCritical
Exit Sub
End If
Loop
End If
formSaisi.Show vbModal
If formSaisi.Checbut.Value = True Then
tit = formSaisi.lisAge.List(formSaisi.lisAge.ListIndex, 0)
tit1 = formSaisi.listAct.List(formSaisi.listAct.ListIndex, 0)
With Sheets("SUIVI")
.Range("c" & lig).Value = formSaisi.saisDat.Value
.Range("d" & lig).Value = tit
.Range("f" & lig).Value = formSaisi.infMet.Caption
.Range("g" & lig).Value = tit1
.Range("k" & lig).Value = formSaisi.listGest.List(formSaisi.listGest.ListIndex, 0)
.Range("l" & lig).Value = formSaisi.listDesc.List(formSaisi.listDesc.ListIndex, 0)
.Range("M" & lig & ":N" & lig).NumberFormat = "[$-fr-FR]d-mmm-yy;@"
.Range("Q" & lig & ":S" & lig).NumberFormat = "[$-fr-FR]d-mmm-yy;@"
.Range("M" & lig & ":S" & lig).Locked = False
.Range("M" & lig & ":S" & lig).FormulaHidden = False
.Range("i" & lig & ":j" & lig).Locked = False
.Range("i" & lig & ":j" & lig).FormulaHidden = False
With .Range("I" & lig).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="Oui;Non"
End With
With .Range("j" & lig).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="Réussite;Échec;Prochainement"
End With
b = 6
Do While Sheets("Liste des ACTIONS").Range("c" & b).Value <> "" 'saisi colonne acteurs
If tit1 = Sheets("Liste des ACTIONS").Range("c" & b).Value Then
.Range("h" & lig).Value = Sheets("Liste des ACTIONS").Range("d" & b).Value
Exit Do
End If
b = b + 1
If b = 10000 Then Exit Do
Loop
b = 6
Do While Sheets("Informations personnelles").Range("c" & b).Value <> "" 'saisi colonne secteur
If tit = Sheets("Informations personnelles").Range("c" & b).Value Then
.Range("e" & lig).Value = Sheets("Informations personnelles").Range("g" & b).Value
Exit Do
End If
b = b + 1
If b = 10000 Then Exit Do
Loop
End With
End If
Unload formSaisi
Sheets("SUIVI").Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets("SUIVI").EnableSelection = xlUnlockedCells
End Sub |
Vous trouverez ci dessus le code qui fonctionne sans problème mais j'ai un petit soucis sur cette partie :
Code:
1 2 3 4 5 6 7 8
| With .Range("I" & lig).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="Oui;Non"
End With
With .Range("j" & lig).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="Réussite;Échec;Prochainement"
End With |
elle consiste à créer sur une cellule une liste de choix avec les éléments "oui" ou "non".
Et pour l'autre cellule une liste de choix avec les éléments "Réussite" ou "échec" ou "prochainement"
J'ai utilisé l'enregistreur de macro pour récupérer les méthodes et j'ai supprimé le superflus.
Après le test j’obtiens qu'un seul choix : "Oui;Non" pour l'une et pour l'autre j'ai qu'un seul choix "Réussite, échec prochainement.".
J'enlève la protection et je vais sur validation des données pour vérifier mon contenu, tout va bien.
Je ferme et je reviens en mode utilisateur je me retrouve avec tous mes choix comme je l'attendais !!!!
Pourquoi cela ne fonctionne pas du premier coup ?
Car l'utilisateur ne va pas faire la manip que j'ai fait à chaque fois .
Merci pour votre aide,
créer sa propre liste en vba avec validation de données
Bonjour
Formula1:="Réussite,Échec,Prochainement"
il faut mettre des virgules et non des points virgule
A+ François