Bonjour à tous,
Je lance des recherches avec un code sur un USERFORM sur plusieurs feuilles, tout fonctionnai à merveille, mais aujourd'hui j’ai un code d’erreur 91 Variable Objet ou Variable bloc With non définie suite a la création de 3 nouvelles feuilles.
Je n’arrive pas à comprendre pourquoi cela ne fonctionne plus.
Private Sub CommandButton1_Click()
Dim F As Worksheet
Dim Plage As Range, C As Range
Dim T As String, Firstaddress As String
Dim x As Integer
ListBox1.Clear
T = Me.TextBox1
If T = "" Then Exit Sub
For Each F In Worksheets
With F
Set Plage = Application.Intersect(.UsedRange.Cells, .Range(.Cells(8, 1), .Cells(.Rows.Count, .Columns.Count)))
End With
Set C = Plage.Find(T, LookIn:=xlValues, LookAt:=xlPart)
If Not C Is Nothing Then
Firstaddress = C.Address
Do
With ListBox1
.AddItem F.Name
For x = 2 To 6
.List(.ListCount - 1, x - 1) = F.Cells(C.Row, x).Text
Next x
.List(.ListCount - 1, 6) = C.Address(False, False)
End With
Set C = Plage.FindNext(C)
Loop While Not C Is Nothing And C.Address <> Firstaddress
End If
Next F
If ListBox1.ListCount = 0 Then
MsgBox "Le Texte " & T & " n'a pas été trouvé" & vbLf & "Faites un essai sur une partie du nom", vbCritical, Sign
End If
End Sub
d'avance merci pour votre aide.
Stéphane
Je lance des recherches avec un code sur un USERFORM sur plusieurs feuilles, tout fonctionnai à merveille, mais aujourd'hui j’ai un code d’erreur 91 Variable Objet ou Variable bloc With non définie suite a la création de 3 nouvelles feuilles.
Je n’arrive pas à comprendre pourquoi cela ne fonctionne plus.
Private Sub CommandButton1_Click()
Dim F As Worksheet
Dim Plage As Range, C As Range
Dim T As String, Firstaddress As String
Dim x As Integer
ListBox1.Clear
T = Me.TextBox1
If T = "" Then Exit Sub
For Each F In Worksheets
With F
Set Plage = Application.Intersect(.UsedRange.Cells, .Range(.Cells(8, 1), .Cells(.Rows.Count, .Columns.Count)))
End With
Set C = Plage.Find(T, LookIn:=xlValues, LookAt:=xlPart)
If Not C Is Nothing Then
Firstaddress = C.Address
Do
With ListBox1
.AddItem F.Name
For x = 2 To 6
.List(.ListCount - 1, x - 1) = F.Cells(C.Row, x).Text
Next x
.List(.ListCount - 1, 6) = C.Address(False, False)
End With
Set C = Plage.FindNext(C)
Loop While Not C Is Nothing And C.Address <> Firstaddress
End If
Next F
If ListBox1.ListCount = 0 Then
MsgBox "Le Texte " & T & " n'a pas été trouvé" & vbLf & "Faites un essai sur une partie du nom", vbCritical, Sign
End If
End Sub
d'avance merci pour votre aide.
Stéphane