Placer résultat TextBox suivant sélection ComboBox dans cellules

Résolu/Fermé
Yoyo01000 Messages postés 1639 Date d'inscription samedi 2 février 2019 Statut Membre Dernière intervention 7 mars 2022 - 27 déc. 2020 à 12:55
Yoyo01000 Messages postés 1639 Date d'inscription samedi 2 février 2019 Statut Membre Dernière intervention 7 mars 2022 - 27 déc. 2020 à 13:54
Bonjour le forum,

Je n'arrive pas à placer le résultat d'une TextBox dont la valeur sera un nombre dans une cellule liée au mois sélectionné dans la ComboBox.

Si par exemple je sélectionne Janvier dans la ComboBox et que j'inscris 35 dans la TextBox, j'aimerais qu'en cellule S1 il y ait le résultat 35.

Et ainsi de suite pour les autres 11 mois de l'année.

Voici le fichier : https://www.cjoint.com/c/JLBl3upumpK


Configuration: Windows / Chrome 87.0.4280.88

3 réponses

cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 728
27 déc. 2020 à 13:36
Bonjour,

sers toi de la propriété ListIndex de ta combobox


Private Sub CommandButton1_Click()
Range("S" & Mois.ListIndex + 1) = TextBox1.Text
End Sub


1
Yoyo01000 Messages postés 1639 Date d'inscription samedi 2 février 2019 Statut Membre Dernière intervention 7 mars 2022 165
27 déc. 2020 à 13:51
Bonjour Le Pivert ,

Tellement plus simple ainsi...!

Merci et bonne fêtes à toi :-)
0
Patrice33740 Messages postés 8556 Date d'inscription dimanche 13 juin 2010 Statut Membre Dernière intervention 2 mars 2023 1 775
27 déc. 2020 à 13:37
Bonjour Yoyo,

Par exemple :
Private Sub CommandButton1_Click()
  If Me.Mois.ListIndex >= 0 And Me.TextBox1.Value <> "" Then
    With ThisWorkbook.Worksheets("Feuil1").Range("S1")
      .Offset(Me.Mois.ListIndex).Value = Val(Me.TextBox1.Value)
    End With
  End If
End Sub 

1
Yoyo01000 Messages postés 1639 Date d'inscription samedi 2 février 2019 Statut Membre Dernière intervention 7 mars 2022 165
27 déc. 2020 à 13:54
Bonjour Patrice ,
au final, j'ai utilisé la solution de Le Pivert avant de voir ta réponse !

Voici le code complet que j'ai utilisé, avec la ligne ListIndex proposée :

Private Sub CommandButton1_Click()

Sheets("Datas Jauges").Visible = True
Sheets("Datas Jauges").Activate
Range("S" & Mois.ListIndex + 1) = Nombre.Text
Sheets("Datas Jauges").Visible = False
Unload Charges
Sheets("UEP Polyvalence 2021").Activate

End Sub


Merci pour ta contribution et ton aide, bonnes fêtes de fin d'année à toi :-)
0
Yoyo01000 Messages postés 1639 Date d'inscription samedi 2 février 2019 Statut Membre Dernière intervention 7 mars 2022 165
27 déc. 2020 à 13:32
Du coup, j'ai fait d'une manière un peu archaïque pouvant sans doute être optimisée :
Private Sub CommandButton1_Click()

If Mois.Value = "Janvier" Then
Range("S1").Value = Nombre.Value
Else
If Mois.Value = "Février" Then
Range("S2").Value = Nombre.Value
Else
If Mois.Value = "Mars" Then
Range("S3").Value = Nombre.Value
Else
If Mois.Value = "Avril" Then
Range("S4").Value = Nombre.Value
Else
If Mois.Value = "Mai" Then
Range("S5").Value = Nombre.Value
Else
If Mois.Value = "Juin" Then
Range("S6").Value = Nombre.Value
Else
If Mois.Value = "Juillet" Then
Range("S7").Value = Nombre.Value
Else
If Mois.Value = "Août" Then
Range("S8").Value = Nombre.Value
Else
If Mois.Value = "Septembre" Then
Range("S9").Value = Nombre.Value
Else
If Mois.Value = "Octobre" Then
Range("S10").Value = Nombre.Value
Else
If Mois.Value = "Novembre" Then
Range("S11").Value = Nombre.Value
Else
If Mois.Value = "Décembre" Then
Range("S12").Value = Nombre.Value
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

End Sub

0