Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default search function without error if not found

I have a search function that I intend to use for several variables. I wonder
how you write the search function so that you do not get error if search is
unsuccessful but rather an informative message box or likewise. My code so
far is:
Private Sub findQC()
Dim rng As Range
Dim findVal As String
Dim i As Integer
Set rng = Worksheets("Dimension").Cells.Find("qc", LookIn:=xlValues)
i = 0
Do Until IsEmpty(rng.Offset(i + 1, 0)) = True
i = i + 1
Loop
End Sub

It is the Set rng = ... that fails if search is unsucessful. Very thakful
for fast assistance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default search function without error if not found

You are incorrect.

Set rng = Worksheets("Dimension").Cells.Find("qc", LookIn:=xlValues)

does not raise an error if the target is not found. Assuming that it
contains a reference later in your code is probably the source of your problem

Private Sub findQC()
Dim rng As Range
Dim findVal As String
Dim i As Integer
Set rng = Worksheets("Dimension").Cells.Find("qc", LookIn:=xlValues)
if not rng is nothing then
i = 0
Do Until IsEmpty(rng.Offset(i + 1, 0)) = True
i = i + 1
Loop
else
msgbox "QC was not found"
end if
End Sub

--
Regards,
Tom Ogilvy


"anderssweden" wrote:

I have a search function that I intend to use for several variables. I wonder
how you write the search function so that you do not get error if search is
unsuccessful but rather an informative message box or likewise. My code so
far is:
Private Sub findQC()
Dim rng As Range
Dim findVal As String
Dim i As Integer
Set rng = Worksheets("Dimension").Cells.Find("qc", LookIn:=xlValues)
i = 0
Do Until IsEmpty(rng.Offset(i + 1, 0)) = True
i = i + 1
Loop
End Sub

It is the Set rng = ... that fails if search is unsucessful. Very thakful
for fast assistance.

Reply
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
search a row for a word and if found Vibeke Excel Worksheet Functions 2 April 16th 10 10:09 AM
SEARCH function returning #VALUE! error jhchan Excel Discussion (Misc queries) 1 May 25th 09 04:36 PM
File or function not found error davegb Excel Programming 2 October 17th 05 06:06 PM
The search key was not found error Nydia New Users to Excel 0 April 27th 05 03:09 PM
Trim Function - Error Library Not Found Doug[_11_] Excel Programming 5 June 30th 04 04:43 AM


All times are GMT +1. The time now is 07:57 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"