Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default error handling

Hi all,
I have a simple sub that lets users input a name in a input box and it will
find the name in a list(and move one cell right for data input.
One problem: fatal error 91 happens when a name is entered that does not
match the list where I'd prefer a msgbox or just returning to the input
box.
Second problem is the name lookup. Using the Find method if user enters
"ones" it will find "ones", and "jones" and "phones" where I would want to
find just the names that begin with the letters typed into the input box.
I've included the code and any help is always appreciated.

Dim pname As String
'user enters name or partial name a sub finds it in a list
pname =inputbox("Enter name")
' this if handles cancel and no entry to inputbox
If pname = "" Then Exit Sub
Range("a3:a147").Select
Selection.find(What:=pname).Activate
ActiveCell.Offset(0, 1).Range("A1").Select



--
jeffP



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default error handling

One way:

Dim vResult As Variant
Dim rFound As Range
Dim sFoundAddress As String
Dim pName As String
Dim bValid As Boolean

Do
vResult = Application.InputBox("Enter name", Type:=2)
If vResult = False Then Exit Sub 'User cancelled
Loop Until vResult < ""
With Range("A3:A147")
Set rFound = .Cells.Find( _
What:=vResult, _
LookIn:=xlValues, _
LookAt:=xlPart, _
MatchCase:=True)
If Not rFound Is Nothing Then
sFoundAddress = rFound.Address
Do
With rFound
If (.Text = vResult) Or (.Text Like vResult & " *") Or _
(.Text Like "* " & vResult) Or _
(.Text Like "* " & vResult & " *") Then bValid = True
End With
If Not bValid Then Set rFound = _
.Cells.FindNext(after:=rFound)
Loop Until bValid Or rFound.Address = sFoundAddress
End If
If bValid Then
rFound.Offset(0, 1).Select
Else
MsgBox vResult & " not found"
End If
End With


In article ,
"jeffP" wrote:

Hi all,
I have a simple sub that lets users input a name in a input box and it will
find the name in a list(and move one cell right for data input.
One problem: fatal error 91 happens when a name is entered that does not
match the list where I'd prefer a msgbox or just returning to the input
box.
Second problem is the name lookup. Using the Find method if user enters
"ones" it will find "ones", and "jones" and "phones" where I would want to
find just the names that begin with the letters typed into the input box.
I've included the code and any help is always appreciated.

Dim pname As String
'user enters name or partial name a sub finds it in a list
pname =inputbox("Enter name")
' this if handles cancel and no entry to inputbox
If pname = "" Then Exit Sub
Range("a3:a147").Select
Selection.find(What:=pname).Activate
ActiveCell.Offset(0, 1).Range("A1").Select

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
Error Handling Kevin Excel Discussion (Misc queries) 4 June 19th 08 12:31 AM
Error Handling bw Excel Programming 3 June 20th 04 06:43 PM
Error Handling Todd Excel Programming 1 February 13th 04 11:29 PM
Error handling John Pierce Excel Programming 3 October 3rd 03 12:17 PM
Error Handling Rob Bovey Excel Programming 0 August 7th 03 12:11 AM


All times are GMT +1. The time now is 11:53 AM.

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

About Us

"It's about Microsoft Excel"