bonjour à tous,

mon problème est le suivant :

Je cherche à remplir mon MSFlexGrid avec les valeurs comprises dans ma Feuil1, en fonction du contenu de ma combobox.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Private Sub CommandButton1_Click()
 
For i = 1 To 50
    ComboBox1.AddItem Range("A" & i + 1).Value
    MSFlexGrid1.TextMatrix(i, 0) = ComboBox1.Value 'erreur d'indice ici
    MSFlexGrid1.Row = i
    MSFlexGrid1.Col = 1
 
    If Range("B" & i).Value = "" Then
        MSFlexGrid1.Row = i
        MSFlexGrid1.Col = 1
        MSFlexGrid1.TextMatrix(i, 1) = "pas d'indice"
    Else
        MSFlexGrid1.TextMatrix(i, 1) = Range("B" & i + 1).Value
    End If
Next i
End Sub
 
Private Sub UserForm_Activate()
Sheets("Feuil1").Select
 
Range("A1:B50").Select
MSFlexGrid1.TextMatrix(0, 0) = "Trucs"
MSFlexGrid1.TextMatrix(0, 1) = "Choses"
    ComboBox1.AddItem Range("A" & i + 1).Value
 
End Sub
On m'a dit qu'il fallait faire une boucle mais je ne suis pas competant dasn ce domaine. (j'ai soif d'apprendre )
je vous joins le fichier pour être plus claire.

Ceci est un exemple, ma macro finale contient 8 colonnes, 600lignes et 5 ComboBox, mais j'aimerai pouvoir l'adapter.