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
| Private Sub CommandButton1_Click()
Dim FoundCount As Double
Dim rFoundB As Range, rFoundC As Range
Dim rFoundD As Range, MyTextB As String
Dim MyTextC As String, MyTextD As String
Dim B As Range, C As Range, D As Range
Dim rB As Range, rC As Range, rD As Range
MyTextB = Me.txtfindB.Value 'j'utiliserais Trim ici une bonne fois pour toute MyTextB = Trim(Me.txtfindB.text)
txtresult.MultiLine = True
'On vide le contenu du txt
txtresult.Text = ""
'Si tu utilise un combobox
ComboBox1.Clear
'On vide le contenu des cellules de A2 jusqu'à la fin du tableau en colonne F
'Sheets("Sheet2").Range("A2:f65536").ClearContents
Sheets("Sheet2").Range("A2:F" & Rows.Count).ClearContents 'compatible avec Excel 2007 (qui a plus de 65536 lignes)
If Trim(MyTextB) <> "*" Then
'With Worksheets("BT")
' Set rB = .Range("b1:b65536")
'End With
'Set rB = Worksheets("BT").Range("b1:b65536") 'ou encore mieux si tu veux faire reference a une colonne complete
Set rB = Worksheets("BT").Range("B:B")
'Set rFoundB = rB.Resize(1, 1) '? 'ca correspond simplement a range("B1")
Set B = rB.Find(MyTextB, LookIn:=xlValues, Lookat:=xlPart) 'Set B = rB.Find(MyTextB, After:=rFoundB, LookIn:=xlValues, Lookat:=xlPart)
If Not B Is Nothing Then
firstAddress = B.Address
Do
bcopy = False '??
If (InStr(1, B.Offset(0, 1), Trim(MyTextC), vbTextCompare) > 0 _
Or Trim(MyTextC) = "*" _
Or Trim(MyTextC) = "") And _
(InStr(1, B.Offset(0, 2), Trim(MyTextD), vbTextCompare) > 0 _
Or Trim(MyTextD) = "*" Or Trim(MyTextD) = "") Then
'ici on renseigne la feuille 2
lr = Sheets("Sheet2").Cells(Rows.Count, "a").End(xlUp).Row + 1 'attention lr n'est pas declaré? il doit etre déclaré As Long
B.EntireRow.Copy Sheets("Sheet2").Rows(lr)
FoundCount = FoundCount + 1
'Je suppose qu'ici tu veux rajouter des entrée dans ton txt
If txtresult.Text <> "" Then txtresult.Text = txtresult.Text & vbCrLf 'On rajout un retour a la ligne si une entrée est deja presente
txtresult.Text = txtresult.Text & B.Value
'... j'utiliserais plutot utiliser un ComboBox
ComboBox1.AddItem B.Value
End If
Set B = rB.FindNext(B)
Loop While Not B Is Nothing And B.Address <> firstAddress
End If ' not B is Nothing
End If
MsgBox FoundCount & " valeurs trouvés", vbInformation, "Transfert complété"
'Sheets("Sheet2").Select
End Sub |
Partager