G
Garage2k
Hi everyone im new here so be kind.
Im trying to produce a seach function in VBA that will search a given
column i.e. "H" for a particular word then when it finds this it then
puts the entire row in which it is found into a textbox i.e. A1:H1
I have managed to do this however i encounter problems when a word is
searched for and not found i get
"runtime error 91 Object variable or with block not set"
Here's the code so far albeit fairly primitive.
Private Sub CommandButton1_Click()
ListBox1.Clear
searchcount = 0
description.Hide
Sheets("Sheet1").Select
Columns("H:H").Select
Selection.Find(What:=TextBox1, After:=ActiveCell, LookIn:=xlValues,
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False).Activate
temp = ActiveCell.Address
countrow = ActiveCell.Row
ListBox1.AddItem Range("A" & countrow).Text & " ¦ " & Range("B" &
countrow).Text & " ¦ " & Range("C" & countrow).Text & " ¦ " &
Range("D" & countrow).Text & " ¦ " & Range("E" & countrow).Text & "
¦ " & Range("F" & countrow).Text & " ¦ " & Range("G" &
countrow).Text & " ¦ " & Range("H" & countrow).Text
Selection.FindNext(After:=ActiveCell).Activate
Do Until ActiveCell.Address = temp
countrow = ActiveCell.Row
ListBox1.AddItem Range("A" & countrow).Text & " ¦ " & Range("B" &
countrow).Text & " ¦ " & Range("C" & countrow).Text & " ¦ " &
Range("D" & countrow).Text & " ¦ " & Range("E" & countrow).Text & "
¦ " & Range("F" & countrow).Text & " ¦ " & Range("G" &
countrow).Text & " ¦ " & Range("H" & countrow).Text
Selection.FindNext(After:=ActiveCell).Activate
searchcount = searchcount + 1
Loop
theend:
description.Show
End Sub
Im trying to produce a seach function in VBA that will search a given
column i.e. "H" for a particular word then when it finds this it then
puts the entire row in which it is found into a textbox i.e. A1:H1
I have managed to do this however i encounter problems when a word is
searched for and not found i get
"runtime error 91 Object variable or with block not set"
Here's the code so far albeit fairly primitive.
Private Sub CommandButton1_Click()
ListBox1.Clear
searchcount = 0
description.Hide
Sheets("Sheet1").Select
Columns("H:H").Select
Selection.Find(What:=TextBox1, After:=ActiveCell, LookIn:=xlValues,
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False).Activate
temp = ActiveCell.Address
countrow = ActiveCell.Row
ListBox1.AddItem Range("A" & countrow).Text & " ¦ " & Range("B" &
countrow).Text & " ¦ " & Range("C" & countrow).Text & " ¦ " &
Range("D" & countrow).Text & " ¦ " & Range("E" & countrow).Text & "
¦ " & Range("F" & countrow).Text & " ¦ " & Range("G" &
countrow).Text & " ¦ " & Range("H" & countrow).Text
Selection.FindNext(After:=ActiveCell).Activate
Do Until ActiveCell.Address = temp
countrow = ActiveCell.Row
ListBox1.AddItem Range("A" & countrow).Text & " ¦ " & Range("B" &
countrow).Text & " ¦ " & Range("C" & countrow).Text & " ¦ " &
Range("D" & countrow).Text & " ¦ " & Range("E" & countrow).Text & "
¦ " & Range("F" & countrow).Text & " ¦ " & Range("G" &
countrow).Text & " ¦ " & Range("H" & countrow).Text
Selection.FindNext(After:=ActiveCell).Activate
searchcount = searchcount + 1
Loop
theend:
description.Show
End Sub