XL 2010 Recherche et copier par rapport a un textbox

Myst

XLDnaute Occasionnel
Bonjour
Je voudrais faire une recherche dans la colonne A de la page 1 a partir d'un numéro que je saisie dans le textbox1 de userform1 et copier toutes les lignes ayant ce numéro dans la page 2
- si il y en a 0 = message " aucun résultat"
merci
 

thebenoit59

XLDnaute Accro
Bonjour Myst.

Une première solution :
VB:
Private Sub CommandButton2_Click()
Dim n&, i&, k&
n = Me.TextBox1.Value
With Sheets(1)
    For i = 3 To .[a65000].End(xlUp).Row
        If .Cells(i, "A").Value = n Then
            .Range(.Cells(i, "A"), .Cells(i, "L")).Copy Sheets(2).Cells(Sheets(2).[a65000].End(xlUp).Row + 1, 1)
            k = k + 1
        End If
    Next i
End With
If k = 0 Then MsgBox "Aucun résultat"
End Sub
 

Myst

XLDnaute Occasionnel
Bonjour thebenoit59
je voudrais faire une autre recherche sur la colonne C, j'ai donc modifié comme ci-dessous mais ça ne fonctionne pas
VB:
Dim n&, i&, k&
n = Me.TextBox1.Value
With Sheets(1)
    For i = 3 To .[c65000].End(xlUp).Row
        If .Cells(i, "C").Value = n Then
            .Range(.Cells(i, "C"), .Cells(i, "L")).Copy Sheets(2).Cells(Sheets(2).[c65000].End(xlUp).Row + 1, 1)
            k = k + 1
        End If
    Next i
End With
If k = 0 Then MsgBox "Aucun résultat"
 

Discussions similaires

Statistiques des forums

Discussions
312 198
Messages
2 086 132
Membres
103 127
dernier inscrit
willwebdesign