LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find function in VBA


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


--
Garage2k
------------------------------------------------------------------------
Garage2k's Profile: http://www.excelforum.com/member.php...o&userid=26227
View this thread: http://www.excelforum.com/showthread...hreadid=395243

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to find which function to use J4shaw Excel Worksheet Functions 3 August 3rd 09 05:58 AM
Find Function [email protected] Excel Worksheet Functions 2 September 14th 07 08:26 PM
FIND function? Sonya Excel Discussion (Misc queries) 3 October 22nd 05 04:53 AM
Help with the FIND function Ranger Excel Worksheet Functions 1 February 25th 05 03:24 PM
backwards find function to find character in a string of text Ashleigh K. Excel Programming 1 January 14th 04 04:36 PM


All times are GMT +1. The time now is 01:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"