Modification VBA ajout catégorie
je comprend pas de quoi vous faite allusion
mal a m exprimer a l ecrit enfaite je pense
je comprend pas de quoi vous faite allusion
Hum... qu'est ce que vous ne comprenez pas dans mes questions. j'ai mis cela en 4 points dans mon post précédent
Private Sub ComboBox2_Change()
End Sub
Private Sub CommandButton1_Click()
Dim Dat As Date
Dim Dlig2%
Dim dlig%
Dim Arc$
Dim Age As Date
Dim Sexe$
Dim Debu$
Dim sh1 As Worksheet
Arc = ComboBox2
Age = TextBox2
Sexe = ComboBox4
Debu = ComboBox3
Set sh1 = Sheets("Récapitulatif")
Application.ScreenUpdating = False
sh1.Activate
dlig = Columns("A").Find("*", , , , , xlPrevious).Row + 1
If TextBox2 <> "" Then
Dat = Format(TextBox2, "dd/mm/yyyy")
Range("A" & dlig) = TextBox1
Range("B" & dlig) = ComboBox1
Range("C" & dlig) = ComboBox2
Range("D" & dlig) = ComboBox3
Range("E" & dlig) = ComboBox4
Range("F" & dlig) = Dat
If Arc = "P" Then
sh1.Range("G" & dlig) = "15. Poulie"
Sheets("P").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1
ElseIf Age >= DateSerial(2012, 12, 31) Then
If Debu = "Oui" Then
sh1.Range("G" & dlig) = "01. Benjamin(e) Débutant(e)"
Sheets("B-D").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1
Else
sh1.Range("G" & dlig) = "02. Benjamin(e)"
Sheets("B").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1
End If
ElseIf Age >= DateSerial(2011, 1, 1) Then
If Debu = "Oui" Then
sh1.Range("G" & dlig) = "03. Minime Débutant(e)"
Sheets("M-D").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1
Else
sh1.Range("G" & dlig) = "04. Minime"
Sheets("M").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1
End If
ElseIf Age >= DateSerial(2008, 1, 1) Then
If Debu = "Oui" Then
sh1.Range("G" & dlig) = "05. Cadet(te) Débutant(e)"
Sheets("C-D").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1
Else
sh1.Range("G" & dlig) = "06. Cadet(te)"
Sheets("C").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1
End If
ElseIf Age >= DateSerial(2005, 1, 1) Then
If Debu = "Oui" Then
sh1.Range("G" & dlig) = "07. Adultes Débutant(e)"
Sheets("A-D").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1
Else
sh1.Range("G" & dlig) = "08. Junior"
Sheets("J").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1
End If
ElseIf Age >= DateSerial(1975, 1, 1) Then
If Debu = "Oui" Then
sh1.Range("G" & dlig) = "07. Adultes Débutant(e)"
Sheets("A-D").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1
Else
If Sexe = "F" Then
sh1.Range("G" & dlig) = "09. Femme"
Sheets("F").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1
Else
sh1.Range("G" & dlig) = "10. Homme"
Sheets("H").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1
End If
End If
ElseIf Age > DateSerial(1960, 1, 1) Then
If Debu = "Oui" Then
sh1.Range("G" & dlig) = "07. Adultes Débutant(e)"
Sheets("A-D").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1
Else
If Sexe = "F" Then
sh1.Range("G" & dlig) = "11. Vétéran Femme"
Sheets("VF").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1
Else
sh1.Range("G" & dlig) = "12. Vétéran Homme"
Sheets("VH").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1
End If
End If
ElseIf Age <= DateSerial(1960, 12, 31) Then
If Debu = "Oui" Then
sh1.Range("G" & dlig) = "07. Adultes Débutant(e)"
Sheets("A-D").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1
Else
If Sexe = "F" Then
sh1.Range("G" & dlig) = "13. Super Vétéran Femme"
Sheets("SVF").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1
Else
sh1.Range("G" & dlig) = "14. Super Vétéran Homme"
Sheets("SVH").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1
End If
End If
End If
sh1.Activate
Range("A2:G1048576").Select
ActiveWorkbook.Worksheets("Récapitulatif").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Récapitulatif").Sort.SortFields.Add2 Key:=Range _
("A2:A1048576"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Récapitulatif").Sort
.SetRange Range("A2:G1048576")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.Apply
End With
Effac
Unload UserForm1
Else
MsgBox "Veuillez remplir le formulaire entièrement"
End If
Set sh1 = Nothing
Application.ScreenUpdating = True
End Sub
Private Sub CommandButton2_Click()
Effac
End Sub
Sub Effac()
ComboBox1 = ""
ComboBox2 = ""
ComboBox3 = ""
ComboBox4 = ""
TextBox1 = ""
TextBox2 = ""
End Sub
Private Sub Frame2_Click()
End Sub
Private Sub Frame3_Click()
End Subenfaite ici voudrais modifier pour mettre des dates pour faire 2 categorie une adultes poulie et une autre super vétérant poulie
j arrive pas mettre la condition p pour poulie pour creer categorie je c est pas si suis clair
If Arc = "P" Then
sh1.Range("G" & dlig) = "15. Poulie"
Sheets("P").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1oui c est ca condition p j avait pas lu comme il faut
Je n'ai pas besoin de vos codes. Je les ai dans votre fichier
enfaite ici voudrais modifier pour mettre des dates pour faire 2 categorie une adultes poulie et une autre super vétérant poulie
Et donc à chaque fois que vous allez ajouter un catégorie vous allez remodifier le code ??
j arrive pas mettre la condition p pour poulie pour creer categorie je c est pas si suis clair
EDIT : ben justement vous ne sauriez pas créer deux catégories pour la même condition P dans le code.
j ai juste celle si a ajouter du moins en 2 poulie seniors qui reste p donc oui avec date aussi et autre categorie svp avec date avec condition p
j ai pas d autre categorie a rajouter je change juste date decale a chaque début de saison de 1 an
Ok. Si vous n'avez pas d'autre catégorie à ajouter.
Donc j'ai besoin de savoir combien de choix vous pouvez avoir quand vous sélectionnez P
Actuellement dans le code vous avez 15. Poulie
Et de ce que je comprends vous voulez ajoutez 16. xxx
Donc cela fait deux choix soit le 15 ou le 16 ?
esque c est possible de mettre ca a la place du code actuel de poulie ?
>= DateElseIf Age Serial(2005, 1, 1) Then
If Arc = "P" Then
sh1.Range("G" & dlig) ="15. Poulie"
Sheets("P").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1
End If
<= DateSerial(1960, 12, 31) Then
If Arc = "P" Then
sh1.Range("G" & dlig) ="16. Super vétérant Poulie"
Sheets("SVP").Activate
Dlig2 = Columns("A").Find("*", , , , , xlPrevious).Row + 1
Range("A" & Dlig2) = TextBox1
Range("B" & Dlig2) = ComboBox1
End IfOk. Si vous n'avez pas d'autre catégorie à ajouter.
Donc j'ai besoin de savoir combien de choix vous pouvez avoir quand vous sélectionnez P
Actuellement dans le code vous avez 15. Poulie
Et de ce que je comprends vous voulez ajoutez 16. xxx
Donc cela fait deux choix soit le 15 ou le 16 ?
oui c est cela
>= DateElseIf Age Serial(2005, 1, 1) ThenHeu c'est quoi cela ?
je c est pas surment tromper voulais plus mettre ca
ElseIf Age >= DateSerial(2005, 1, 1) Then
je c est pas surment tromper voulais plus mettre ca
excusez moi mais j'ai vraiment difficile à comprendre ce que vous écrivez
Si vous mettez la condition Age avant la condition ARC cela fonctionnera
Donc comme ceci
ElseIf Age >= DateSerial(2005, 1, 1) Then
If Arc = "P" Then
With Range("Récap").ListObject
.ListRows.Add: lig = .ListRows.Count
With .DataBodyRange
.Item(lig, 1) = TextBox1.Text
.Item(lig, 2) = ComboBox1.Text
.Item(lig, 7) = "15. Poulie"
End With
End With
End If
....
....Mais bon après il faut revoir votre code en fonction des tableaux structurés
Mais bon après il faut revoir votre code en fonction des tableaux structurés
c est a dire
Comme je vous l'ai écrit avant avec les tableaux structurés les codes sont différents
Je vais regarder pour vous proposer quelque chose
15 poulie --> La date doit être supérieur au 1/1/2005
16 Super véteran Poulie -> la date doit être inférieure au 31/12/1960
Correct ?
oui c est cela
je vous remercie
Bon on va tester uniquement sur les deux cas 15 et 16
1. Remplacez le code du bouton Ajouter par celui ci-dessous
Private Sub CommandButton1_Click()
Dim cat As String
Dim TS As ListObject
Dim age as date
Dim Arc as string
Dim lig as integer
Set TS = Range("Récap").ListObject
Arc = ComboBox2.text
Application.ScreenUpdating = False
With TS
.ListRows.Add: lig = .ListRows.Count
End With
If TextBox2 <> "" Then
With TS.DataBodyRange
.Item(lig, 1) = TextBox1.Text
.Item(lig, 2) = ComboBox1.Text
.Item(lig, 3) = ComboBox2.Text
.Item(lig, 4) = ComboBox3.Text
.Item(lig, 5) = ComboBox4.Text
.Item(lig, 6) = Format(TextBox2, "dd/mm/yyyy")
End With
If Arc = "P" Then
Select Case Age
Case Is >= DateSerial(2005, 1, 1): cat = "15. Poulie"
Case Is <= DateSerial(1960, 12, 31): cat = "16. Super vétérant Poulie"
End Select
TS.DataBodyRange.Item(lig, 7) = cat
End If
End If
End Sub2. ensuite dans votre fichier posté, avant d'utiliser le code, faites ceci dans la feuille Récap
- Sélectionnez A3 à G224
- clic droite dans la sélection
- choisir l'option Supprimer --> Lignes de tableau.
Vous devez absolument voir cette option "Lignes de tableau"
3. faites un test et dites moi
EDIT : attention j'ai rajouté ARC au début dans le code
j ai pas reussi a mettre
j ai pas reussi a mettre
Comment çà ?
Vous allez dans l'Userform1 et vous remplacez le code Private sub Commandbutton1_click par celui que je vous ai donné.
Suivez les 3 points.
je suppose que c'est vous qui avez fait le code et les USF non ?