Bonjour
Comment Initialiser un ComboBox dans une cellule en VBA ( un peu comme si on faisait une validation avec une liste)
MERCI
Version imprimable
Bonjour
Comment Initialiser un ComboBox dans une cellule en VBA ( un peu comme si on faisait une validation avec une liste)
MERCI
Bonjour,
Tu peux créer ta liste de validation avec VBA (la liste sera alors dans la cellule)
Sinon, tu peux créer une ComboBox dans ta feuille (la liste ne sera pas dans la cellule) ou dans un UserForm.Code:
1
2
3
4
5
6 Sub CreerListe() With Worksheets("Feuil1").Range("A1").Validation .Delete .Add Type:=xlValidateList, Formula1:="Toto,Titi,Tutu,Tata" End With End Sub
http://silkyroad.developpez.com/VBA/ControlesUserForm/
Cordialement.
et on peut remplir la liste par une variable?
Je suppose que tu as déjà essayé cela ;)
Cordialement.Code:
1
2
3
4
5
6
7
8 Sub CreerListe() Dim ListeValid As String ListeValid = "Toto,Titi,Tutu,Tata" With Worksheets("Feuil1").Range("A1").Validation .Delete .Add Type:=xlValidateList, Formula1:=ListeValid End With End Sub
voila la solution
il fait une liste de validation par colonne du array
si >200caracteres il va creer une feuille et installe toutes les valeurs uniques et permet donc de faire une liste
:ccool: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 Dim Tblo() Dim a As Integer, b As Integer With ActiveSheet.Range("a1").CurrentRegion ReDim Tblo(.Rows.Count, .Columns.Count) Tblo = .Value End With Windows("Historic Prices.xls").Close False ThisWorkbook.Activate Range(Cells(1, 1), Cells(1, UBound(Tblo, 2))).Value = Tblo For j = 1 To UBound(Tblo, 2) temp = "" For k = 2 To UBound(Tblo, 1) If InStr(temp, Tblo(k, j)) = 0 And Tblo(k, j) <> "" Then temp = temp & Tblo(k, j) & "," Next Cells(2, j).Select If Len(temp) > 0 And Len(temp) <= 200 Then ActiveCell.Validation.Delete ActiveCell.Validation.Add xlValidateList, Formula1:=Left(temp, Len(temp) - 1) End If If Len(temp) > 200 Then On Error Resume Next Sheets("Search_Data").Select If Err = 9 Then Sheets.Add ActiveSheet.Name = "Search_Data" End If On Error GoTo 0 Dim Tableau() As String Dim i As Integer Tableau = Split(temp, ",") Sheets("Search_Data").Select Range(Cells(1, j), Cells(UBound(Tableau), j)).Value = Application.WorksheetFunction.Transpose(Tableau) Dim maplage As Range Set maplage = Range(Cells(1, j), Cells(UBound(Tableau), j)) ActiveWorkbook.Names.Add Name:="valeur" & j, RefersTo:=maplage