Données sur feuilles excel

Fermé
Ludo1970 Messages postés 2 Date d'inscription dimanche 26 août 2018 Statut Membre Dernière intervention 26 août 2018 - Modifié le 26 août 2018 à 00:20
yg_be Messages postés 22906 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 25 juin 2024 - 26 août 2018 à 10:23
Bonjour,
Est-t'il possible de reprendre une zone de cellule pour faire un bout de code plus court que:

If ComboBox1.Value = "214510100" Then UserForm2.Show
If ComboBox1.Value = "214510150" Then UserForm2.Show
If ComboBox1.Value = "214510200" Then UserForm2.Show
If ComboBox1.Value = "214510300" Then UserForm2.Show
If ComboBox1.Value = "214510400" Then UserForm2.Show


*

If ComboBox1.Value = "214510500" Then UserForm3.Show
If ComboBox1.Value = "214510600" Then UserForm3.Show
If ComboBox1.Value = "214510800" Then UserForm3.Show
If ComboBox1.Value = "214520010" Then UserForm3.Show


*

If ComboBox1.Value = "274510100" Then UserForm4.Show
If ComboBox1.Value = "274510150" Then UserForm4.Show
If ComboBox1.Value = "274510200" Then UserForm4.Show
If ComboBox1.Value = "274510300" Then UserForm4.Show


*

If ComboBox1.Value = "223520015" Then UserForm5.Show
If ComboBox1.Value = "223520016" Then UserForm5.Show
If ComboBox1.Value = "223520018" Then UserForm5.Show
If ComboBox1.Value = "223520020" Then UserForm5.Show
If ComboBox1.Value = "223520025" Then UserForm5.Show

Ce qui fait que selon le résultat de la comboBox1 c'est un UserForm qui s’ouvre.

En gros, je veux écrire sur une feuille excel les données 214510100; 214510200; 214510300 etc...

En gros un code dans ce genre:
If ComboBox1.Value ("A1:A6") Then Userform1.Show
If ComboBox1.Value ("A7:A10") Then Userform2.Show
If ComboBox1.Value ("A11:A14") Then Userform3.Show

D'avance MERCI
A voir également:

3 réponses

Frenchie83 Messages postés 2240 Date d'inscription lundi 6 mai 2013 Statut Membre Dernière intervention 11 août 2023 338
26 août 2018 à 05:16
Bonjour,
Exemples:
1- Avec les valeurs:
    Select Case ComboBox1.Text
        Case Is = "214510100", "214510150", "214510200", "214510300", "214510400"
            UserForm2.Show
        Case Is = "214510500", "214510600", "214510800", "214520010"
            UserForm3.Show
        Case Is = "274510100", "274510150", "274510200", "274510300"
            UserForm4.Show
        Case Is = "223520015", "223520016", "223520018", "223520020", "223520025"
            UserForm5.Show
    End Select


2- Avec les cellules
    Select Case ComboBox1
        Case Is = CStr([A1]), CStr([A2]), CStr([A3]), CStr([A4]), [A5], CStr([A6])
            UserForm1.Show
        Case Is = CStr([A7]), CStr([A8]), CStr([A9]), CStr([A10])
            UserForm2.Show
        Case Is = CStr([A11]), CStr([A12]), CStr([A13]), CStr([A14])
            UserForm3.Show
    End Select


Cdlt
0
Ludo1970 Messages postés 2 Date d'inscription dimanche 26 août 2018 Statut Membre Dernière intervention 26 août 2018
26 août 2018 à 10:23
Salut Frenchie83,
Merci pour ta réponse. Donc si je comprends bien, pas moyen de sélectionner une plage de cellule, voir une plage de cellule nommée.
0
yg_be Messages postés 22906 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 25 juin 2024 1 480
26 août 2018 à 10:23
bonjour, suggestion:
If Not IsError(Application.Match(ComboBox1.Value, [A1:A6], 0)) Then
   Userform1.Show
ElseIf Not IsError(Application.Match(ComboBox1.Value, [A7:A10], 0)) Then
    Userform2.Show
ElseIf Not IsError(Application.Match(ComboBox1.Value, [A11:A14], 0)) Then
    Userform3.Show
End If
0