Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 85
Default InputBox - finding the input in a range

I am prompting the user for a numeric value with an inputbox. He
Answer = Application.InputBox(Prompt:="What is the Number?", Type:=1)

I then use cells.find command to search a range (column) for the numeric
value.
He
Cells.Find(What:="Answer", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

It searches the range, but it returns the error "Object variable not set."
However, if I had used the "SET" command for the variable "Answer", the type
wouldn't match, because that requires a "range" type variable, not a numeric
value.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default InputBox - finding the input in a range

What happen if you remove the quote marks from around the word Answer in the
What parameter (that is, specify the contents of the variable and not the
piece of text "Answer")?

Rick


"ManhattanRebel" wrote in message
...
I am prompting the user for a numeric value with an inputbox. He
Answer = Application.InputBox(Prompt:="What is the Number?", Type:=1)

I then use cells.find command to search a range (column) for the numeric
value.
He
Cells.Find(What:="Answer", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

It searches the range, but it returns the error "Object variable not set."
However, if I had used the "SET" command for the variable "Answer", the
type
wouldn't match, because that requires a "range" type variable, not a
numeric
value.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default InputBox - finding the input in a range

Basically it is failing because it cannot find the string Answer. You have
used Answer as a variable so don't use the double quotes in the find.

Cells.Find(What:=Answer, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

You should realize that you will always get an error in the above code if
the value is not found. You need to use set then test the set variable for
Not Nothing as follows.

Sub test()
Dim Answer
Dim foundAnswer

Answer = Application.InputBox _
(Prompt:="What is the Number?", Type:=1)

Set foundAnswer = Cells.Find(What:=Answer, _
After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

If Not foundAnswer Is Nothing Then

MsgBox "Value of foundAnswer is " _
& foundAnswer.Value

MsgBox "Address of foundAnswer is " _
& foundAnswer.Address
Else
MsgBox "Value " & Answer & " Not found"
End If

End Sub

--
Regards,

OssieMac


"ManhattanRebel" wrote:

I am prompting the user for a numeric value with an inputbox. He
Answer = Application.InputBox(Prompt:="What is the Number?", Type:=1)

I then use cells.find command to search a range (column) for the numeric
value.
He
Cells.Find(What:="Answer", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

It searches the range, but it returns the error "Object variable not set."
However, if I had used the "SET" command for the variable "Answer", the type
wouldn't match, because that requires a "range" type variable, not a numeric
value.

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
put inputbox input into a cell Dave F Excel Programming 5 April 23rd 07 05:18 PM
Check on the input in an inputbox Tempy Excel Programming 5 May 17th 05 02:01 PM
Numerical Input via an inputbox method Tom Ogilvy Excel Programming 0 August 16th 04 07:33 PM
Numerical Input via an inputbox method Bob Phillips[_6_] Excel Programming 0 August 16th 04 07:30 PM
Check on the input in an inputbox Les Stout Excel Programming 2 January 14th 04 03:18 PM


All times are GMT +1. The time now is 11:08 PM.

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"