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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| Option Explicit
Dim NbreCol As Long
Private Sub CommandButton1_Click()
Unload UserForm1
End Sub
Private Sub TextBox1_Change()
Dim S As String, i As Long, Lmax As Long, Nbr As Long, k As Long
Dim L, V, LigneOK, m, A As Long '<<< ligne modifiée
NbreCol = 13 '<---- Nombre de colonnes à prendre en compte
If TextBox1 = "" Then
init
Else
UserForm1.TextBox2 = ""
ListBox1.Clear
Lmax = Range("A" & Rows.Count).End(xlUp).Row
V = Range(Range("A2"), Cells(Lmax, NbreCol)).Value
ReDim LigneOK(1 To Lmax - 1) '<<< ligne modifiée
'-------------------------------------------------------------------------------------'
' si on ne veut qu'une présence du texte saisi en début de cellule, conserver l'instruction suiv.
'S = LCase(TextBox1) & "*"
' si le texte saisi peut se trouver n'importe où dans les cellules, conserver l'instructiion suiv.
'S = S = "*" & LCase(TextBox1) & "*"
'-------------------------------------------------------------------------------------'
S = "*" & LCase(TextBox1) & "*"
For i = 1 To Lmax - 1
For m = 1 To NbreCol '<<< ligne modifiée
LigneOK(i) = False '<<< ligne modifiée
If LCase(V(i, m)) Like S Then '<<< ligne modifiée
LigneOK(i) = True '<<< ligne modifiée
Nbr = Nbr + 1 '<<< ligne modifiée
Exit For '<<< ligne modifiée
End If '<<< ligne modifiée
Next m '<<< ligne modifiée
Next i
If Nbr = 0 Then Exit Sub
ReDim L(0 To Nbr - 1, 0 To NbreCol - 1)
Nbr = -1
For i = 1 To Lmax - 1
If LigneOK(i) Then '<<< ligne modifiée
Nbr = Nbr + 1
For k = 0 To NbreCol - 1
L(Nbr, k) = V(i, k + 1)
Next k
End If
Next i
ListBox1.List = L
A = ListBox1.ListCount
End If
Label1 = ListBox1.ListCount
End Sub
Private Sub TextBox2_Change()
Dim S As String, j As Long, Lma As Long, Nbr As Long, k As Long
Dim D, V, U, LigneOK, m As Long '<<< ligne modifiée
Dim L1 As Range
NbreCol = 13 '<---- Nombre de colonnes à prendre en compte
If TextBox2 = "" Then
Else
j = 1
Lma = 0
Nbr = 0
k = 0
D = 0
V = 0
U = 0
m = 0
LigneOK = 0
Lma = ListBox1.ListCount
'Feuil2.Range(Range("A2"), Cells(Lma, NbreCol)).Value = ListBox1.Value
Set L1 = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp).Offset(, 2))
'Set U = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp).Offset(, 2))
L1.Value = ListBox1.List
U = Range(Range("A2"), Cells(Lma, NbreCol)).Value
ReDim LigneOK(1 To Lma) '<<< ligne modifiée
S = "*" & LCase(TextBox2) & "*"
For j = 1 To Lma - 1
For m = 1 To NbreCol '<<< ligne modifiée
LigneOK(j) = False '<<< ligne modifiée
If LCase(U(j, m)) Like S Then '<<< ligne modifiée
LigneOK(j) = True '<<< ligne modifiée
Nbr = Nbr + 1 '<<< ligne modifiée
Exit For '<<< ligne modifiée
End If '<<< ligne modifiée
Next m '<<< ligne modifiée
Next j
If Nbr = 0 Then Exit Sub
ReDim D(0 To Nbr - 1, 0 To NbreCol - 1)
Nbr = -1
For j = 1 To Lma - 1
If LigneOK(j) Then '<<< ligne modifiée
Nbr = Nbr + 1
For k = 0 To NbreCol - 1
D(Nbr, k) = U(j, k + 1)
Next k
End If
Next j
ListBox1.List = D
End If
Label1 = ListBox1.ListCount
End Sub
Sub init()
Dim xRg As Range
Set xRg = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp).Offset(, 2))
'ListBox1.ColumnHeads = False
ListBox1.List = xRg.Value
ListBox1.Activate
TextBox1.Activate
End Sub
Private Sub UserForm_Click()
End Sub |
Partager