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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| Option Explicit
Dim f, f2, BD(), choix(), rng, Ncol, NcolInt, colVisu(), colInterro(), Decal
Dim Ligne_Data_LOOK As String
Private Sub UserForm_Initialize()
Dim LargeurCol()
Dim col As Variant
Dim i As Variant
Dim k As Variant
Dim c As Variant
Dim Date_maj As Date
Dim Cmde_Ext As Variant
'Centrer userform sur le fichier excel et non sur l'écran
'Régler StartUpPosition 0-Manual
Me.Left = Application.Left + Application.Width / 2 - Me.Width / 2 'Pour centrer sur l'application Application.Left + Application.Width / 2 - Me.Width / 2
Me.Top = Application.Top + 50 'Application.Height / 2 - Me.Height / 2 'Pour centrer sur l'application Application.Top + Application.Height / 2 - Me.Height / 2
'TextBox1 est une ComboBox pour éviter de remplacer le texte dans toutes les macros
' Importer.Importation_Fournisseurs 'Actualisation des data
On Error Resume Next 'si la liste est vide
Set f = ThisWorkbook.Sheets("Data_Fournisseurs")
Me.TextBox1.List = f.Range("TS_Data_Fournisseurs") 'Minimum 4 colonnes dans le tableau
Set rng = f.Range("TS_Data_Fournisseurs") 'Minimum 4 colonnes dans le tableau
Me.ListBox1.ColumnCount = 10 'Minimum 4 colonnes dans le tableau
colVisu = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) 'Numéros des colonnes à afficher
LargeurCol = Array(0, 0, 0, 80, 80, 80, 80, 180, 150, 200) 'largeur des colonnes, 0 pour masquer l'ID et l'adresse de la ligne Data
Me.ListBox1.ColumnWidths = Join(LargeurCol, ";")
Dim entetes() As Variant
entetes = Array("En-tête de colonne 1", "En-tête de colonne 2", "En-tête de colonne 3", _
"En-tête de colonne 4", "En-tête de colonne 5", "En-tête de colonne 6", _
"En-tête de colonne 7", "En-tête de colonne 8", "En-tête de colonne 9", _
"En-tête de colonne 10")
colInterro = Array(3) 'Numéro de la colonne dans laquelle rechercher
Decal = rng.Row - 1 'Début de la base de donnée
BD = rng.Value
col = UBound(BD, 2): For i = LBound(BD) To UBound(BD): BD(i, col) = i + Decal: Next i 'no enreg
NcolInt = UBound(colInterro) + 1
Ncol = UBound(colVisu) + 1 'ReDim ancien(1 To 1, 1 To Ncol)
'Génération de choix()
ReDim choix(1 To UBound(BD))
col = UBound(BD, 2)
For i = LBound(BD) To UBound(BD)
For Each k In colInterro
choix(i) = choix(i) & BD(i, k) & "|"
Next k
choix(i) = choix(i) & BD(i, col) & "|" 'no enreg
Next i
'TriS choix, 1, UBound(choix) 'Ne pas trier les dates sont triées dans LOOK
'Valeurs initiales dans ListBox
Dim tbl(): ReDim tbl(1 To UBound(BD), 1 To Ncol + 1)
For i = 1 To UBound(BD)
c = 0
For Each k In colVisu
c = c + 1: tbl(i, c) = BD(i, k)
Next k
c = c + 1: tbl(i, c) = i + Decal
Next i
Me.ListBox1.List = tbl
Me.ListBox1.ListIndex = -1
Me.TextBox1.SetFocus 'Placer le curseur dans la recherche
Cmde_Ext = Sheets("Suivi").Cells(ActiveCell.Row, Range("TS_Suivi" & "[Cmde]").Column).Value & " " & Sheets("Suivi").Cells(ActiveCell.Row, Range("TS_Suivi" & "[Ext]").Column).Value
If Cells(Range("TS_Suivi" & "[Cmde]").ListObject.HeaderRowRange.Row, ActiveCell.Column).Value = "Colisage" Then
TextBox1 = Cmde_Ext & " prépa"
Else
TextBox1 = Cmde_Ext
End If
End Sub
Private Sub TextBox1_Change()
Dim Mots, tbl, i, A, j, k, kk, xx As Variant
Mots = Split(Trim(Me.TextBox1), " ")
tbl = choix
For i = LBound(Mots) To UBound(Mots)
tbl = Filter(tbl, Mots(i), True, vbTextCompare)
Next i
If UBound(tbl) > -1 Then
Dim b(): ReDim b(1 To UBound(tbl) + 1, 1 To Ncol + 1)
For i = LBound(tbl) To UBound(tbl)
A = Split(tbl(i), "|")
j = A(NcolInt) - 1 - Decal + 1
For k = 1 To Ncol
kk = colVisu(k - 1)
xx = UBound(BD)
b(i + 1, k) = BD(j, kk)
Next k
b(i + 1, k) = j + 1
Next i
Me.ListBox1.List = b
Else
Me.ListBox1.Clear
End If
Me.Label_Nombre_trouve.Caption = "Trouvé : " & UBound(tbl) + 1
Me.TextBox_Cmde = ""
Me.TextBox_Info_1 = ""
Me.TextBox_Delai_Souhaite = ""
Me.TextBox_Designation = ""
End Sub |
Partager