Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Runtime error using Cell.Find command

Hello,
I have designed a spreadsheet with 24 worksheets. I am trying to design a
macro that will search for a specific date that is embedded inside one of my
worksheets within the workbook. When I run the script below, the Cells.Find
command stalls the macro. Specifically I get the following error --- Runtime
error €˜91: Object variable or with block not set. How do you suggest I fix
this?


Sub test()
Worksheets("LeaveRecord").Activate
ActiveSheet.Next.Select
Cells.Find(What:="11/11/2007").Activate

End Sub

Thanks in advance for your help,
Ellen




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Runtime error using Cell.Find command

Hi Ellen,

Try replacing

Cells.Find(What:="11/11/2007").Activate



with

On Error Resume Next
ActiveSheet.Cells.Find(What:="11/11/2007").Activate
On Error GoTo 0


---
Regards,
Norman


"EllenM" wrote in message
...
Hello,
I have designed a spreadsheet with 24 worksheets. I am trying to design a
macro that will search for a specific date that is embedded inside one of
my
worksheets within the workbook. When I run the script below, the
Cells.Find
command stalls the macro. Specifically I get the following error ---
Runtime
error '91': Object variable or with block not set. How do you suggest I
fix
this?


Sub test()
Worksheets("LeaveRecord").Activate
ActiveSheet.Next.Select
Cells.Find(What:="11/11/2007").Activate

End Sub

Thanks in advance for your help,
Ellen






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Runtime error using Cell.Find command

Working with dates in code can be frustrating.

I'd try:

Dim FoundCell as range
with worksheets("yourworksheetnamehere")
.activate
Set FoundCell = .Cells.Find(what:=dateserial(2007,11,11), _
after:=.Cells(.Cells.Count), _
lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
end with

if foundcell is nothing then
msgbox "not found"
else
foundcell.select
end if


EllenM wrote:

Hello,
I have designed a spreadsheet with 24 worksheets. I am trying to design a
macro that will search for a specific date that is embedded inside one of my
worksheets within the workbook. When I run the script below, the Cells.Find
command stalls the macro. Specifically I get the following error --- Runtime
error €˜91: Object variable or with block not set. How do you suggest I fix
this?


Sub test()
Worksheets("LeaveRecord").Activate
ActiveSheet.Next.Select
Cells.Find(What:="11/11/2007").Activate

End Sub

Thanks in advance for your help,
Ellen



--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Runtime error using Cell.Find command

Hello Dave,
Thanks for your help. I pasted the script and only substituted your
worksheet name with the one I am using. I ran it and got the following error.


Runtime error €˜1004
Activate method of Worksheet class failed



Sub Last_Post()
Dim FoundCell As Range
With Worksheets("2007-pp24")
..Activate
Set FoundCell = .Cells.Find(what:=DateSerial(2007, 11, 11), _
after:=.Cells(.Cells.Count), _
lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
End With

If FoundCell Is Nothing Then
MsgBox "not found"
Else
FoundCell.Select
End If
End Sub

Any suggestions?

Thanks,
Ellen

"Dave Peterson" wrote:

Working with dates in code can be frustrating.

I'd try:

Dim FoundCell as range
with worksheets("yourworksheetnamehere")
.activate
Set FoundCell = .Cells.Find(what:=dateserial(2007,11,11), _
after:=.Cells(.Cells.Count), _
lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
end with

if foundcell is nothing then
msgbox "not found"
else
foundcell.select
end if


EllenM wrote:

Hello,
I have designed a spreadsheet with 24 worksheets. I am trying to design a
macro that will search for a specific date that is embedded inside one of my
worksheets within the workbook. When I run the script below, the Cells.Find
command stalls the macro. Specifically I get the following error --- Runtime
error €˜91€„¢: Object variable or with block not set. How do you suggest I fix
this?


Sub test()
Worksheets("LeaveRecord").Activate
ActiveSheet.Next.Select
Cells.Find(What:="11/11/2007").Activate

End Sub

Thanks in advance for your help,
Ellen



--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Runtime error using Cell.Find command

I'm gonna guess that you misspelled "2007-pp24"

Maybe there's an extra space????

And this won't make a difference for the error message, but I should have used

..select
instead of
..activate

(But again, that's not the cause of the 1004 error)

EllenM wrote:

Hello Dave,
Thanks for your help. I pasted the script and only substituted your
worksheet name with the one I am using. I ran it and got the following error.

Runtime error €˜1004
Activate method of Worksheet class failed

Sub Last_Post()
Dim FoundCell As Range
With Worksheets("2007-pp24")
.Activate
Set FoundCell = .Cells.Find(what:=DateSerial(2007, 11, 11), _
after:=.Cells(.Cells.Count), _
lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
End With

If FoundCell Is Nothing Then
MsgBox "not found"
Else
FoundCell.Select
End If
End Sub

Any suggestions?

Thanks,
Ellen

"Dave Peterson" wrote:

Working with dates in code can be frustrating.

I'd try:

Dim FoundCell as range
with worksheets("yourworksheetnamehere")
.activate
Set FoundCell = .Cells.Find(what:=dateserial(2007,11,11), _
after:=.Cells(.Cells.Count), _
lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
end with

if foundcell is nothing then
msgbox "not found"
else
foundcell.select
end if


EllenM wrote:

Hello,
I have designed a spreadsheet with 24 worksheets. I am trying to design a
macro that will search for a specific date that is embedded inside one of my
worksheets within the workbook. When I run the script below, the Cells.Find
command stalls the macro. Specifically I get the following error --- Runtime
error €˜91€„¢: Object variable or with block not set. How do you suggest I fix
this?


Sub test()
Worksheets("LeaveRecord").Activate
ActiveSheet.Next.Select
Cells.Find(What:="11/11/2007").Activate

End Sub

Thanks in advance for your help,
Ellen



--

Dave Peterson


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Runtime error using Cell.Find command

Thanks, so much, Dave. Your script was very, very helpful. We've got it
working now.

Ellen

"Dave Peterson" wrote:

I'm gonna guess that you misspelled "2007-pp24"

Maybe there's an extra space????

And this won't make a difference for the error message, but I should have used

..select
instead of
..activate

(But again, that's not the cause of the 1004 error)

EllenM wrote:

Hello Dave,
Thanks for your help. I pasted the script and only substituted your
worksheet name with the one I am using. I ran it and got the following error.

Runtime error €˜1004€„¢
Activate method of Worksheet class failed

Sub Last_Post()
Dim FoundCell As Range
With Worksheets("2007-pp24")
.Activate
Set FoundCell = .Cells.Find(what:=DateSerial(2007, 11, 11), _
after:=.Cells(.Cells.Count), _
lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
End With

If FoundCell Is Nothing Then
MsgBox "not found"
Else
FoundCell.Select
End If
End Sub

Any suggestions?

Thanks,
Ellen

"Dave Peterson" wrote:

Working with dates in code can be frustrating.

I'd try:

Dim FoundCell as range
with worksheets("yourworksheetnamehere")
.activate
Set FoundCell = .Cells.Find(what:=dateserial(2007,11,11), _
after:=.Cells(.Cells.Count), _
lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
end with

if foundcell is nothing then
msgbox "not found"
else
foundcell.select
end if


EllenM wrote:

Hello,
I have designed a spreadsheet with 24 worksheets. I am trying to design a
macro that will search for a specific date that is embedded inside one of my
worksheets within the workbook. When I run the script below, the Cells.Find
command stalls the macro. Specifically I get the following error --- Runtime
error €˜91€„¢: Object variable or with block not set. How do you suggest I fix
this?


Sub test()
Worksheets("LeaveRecord").Activate
ActiveSheet.Next.Select
Cells.Find(What:="11/11/2007").Activate

End Sub

Thanks in advance for your help,
Ellen



--

Dave Peterson


--

Dave Peterson

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
How do I handle error conditions with the FIND command? mywebaccts (at) PLUGcomcast.net Excel Worksheet Functions 6 August 5th 07 12:14 AM
Listing of cell references from a FIND All command. Joe Excel Discussion (Misc queries) 7 April 29th 07 11:44 AM
Runtime 91 error due to cells.find statement !??! [email protected] Excel Programming 6 October 26th 06 10:21 AM
Excel has a "Find Next" command but no "Find Previous" command. Michael Fitzpatrick Excel Discussion (Misc queries) 2 January 10th 05 11:45 PM
Runtime error 9 in "How to find a date in a range with VBA ?" Martin Los[_3_] Excel Programming 1 November 25th 04 06:55 PM


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