Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
rci rci is offline
external usenet poster
 
Posts: 40
Default three line program...

Hi all...

why would this fail?

Sheets("Sheet1").Select
Range("A1").Select
Result = Cells.Find("12345") '<-error


Runtime Error 91: Object variable or With block variable not set.

Many thanks!

Mike
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default three line program...

Find returns a range object. So you have to "Set" your variable = to that
range.

Sub test()
Dim Result As Range

Set Result = Sheet1.Cells.Find("1234")
If Not Result Is Nothing Then MsgBox Result.Value & vbTab & Result.Address
End Sub

HTH
"rci" wrote:

Hi all...

why would this fail?

Sheets("Sheet1").Select
Range("A1").Select
Result = Cells.Find("12345") '<-error


Runtime Error 91: Object variable or With block variable not set.

Many thanks!

Mike

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default three line program...

One reason is that you're assigning the default property (.Value) of the
range returned by the Cells.Find() method to Result. If Cells.Find()
doesn't find a cell with the target "12345", then there's no object to
get the property from. Hence the Object Variable not set error...

A second possibility is that if you run this from a button in XL97, you
need to make sure the button's Take Focus on Click property is set to
false.

Better:

Dim rFound As Range
Dim Result As Variant

Set rFound = Sheets("Sheet1").Cells.Find("12345")
If Not rFound Is Nothing Then
Result = rFound.Value
Else
MsgBox "Not Found"
End If

Note that you don't have to select anything.





In article ,
rci wrote:

Hi all...

why would this fail?

Sheets("Sheet1").Select
Range("A1").Select
Result = Cells.Find("12345") '<-error


Runtime Error 91: Object variable or With block variable not set.

Many thanks!

Mike

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default three line program...

Find returns a Range object, so you need to use the Set
statement. You might try declaring it first also. its
usually better to do early binding.

Dim Result as Range

Sheets("Sheet1").Select
Range("A1").Select
Set Result = Cells.Find("12345")
-----Original Message-----
Hi all...

why would this fail?

Sheets("Sheet1").Select
Range("A1").Select
Result = Cells.Find("12345") '<-error


Runtime Error 91: Object variable or With block variable

not set.

Many thanks!

Mike
.

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
In Excel program shows a broken line and don't know how to get ri. faleechia2263 Excel Discussion (Misc queries) 1 April 18th 05 06:43 PM
Program line when charting variances? Greg Strong Charts and Charting in Excel 3 March 27th 05 12:23 AM
Is there a program in office to create a line graph? Chris Excel Discussion (Misc queries) 2 January 17th 05 11:38 PM
starting an external program with a command line Jonathan[_5_] Excel Programming 0 September 5th 03 02:29 PM
starting an external program with a command line Jonathan[_5_] Excel Programming 0 September 5th 03 02:20 PM


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