LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Second Find after a first find fails

Greetings! On an Excel Worksheet, A1 thru A5 contain:
6/1/2009
6/2/2009
6/3/2009
6/4/2009
6/12/2009

The following code runs perfectly. But when I uncomment the commented
Selection.Find instruction, I get the following
error message on execution:

"Run-time error '91':
Object variable or With block variable not set."

and the following instruction (at line 22) is highlighted:
Selection.Find(What:=DatePlusOne, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

The code is as follows:

Option Explicit
Sub FindCloseDateTST()
Dim DateMinusOne As Date
Dim DatePlusOne As Date

DateMinusOne = "6/11/2009"
DatePlusOne = "6/13/2009"

Range("A1:A5").Select

On Error GoTo CheckDateP1

' Selection.Find(What:=DateMinusOne, LookIn:=xlFormulas _
' , LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:=xlNext, _
' MatchCase:=False, SearchFormat:=False).Activate

'""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""
CheckDateP1:
Range("A1:A5").Select
On Error GoTo DateNotFound

' And here is Line 22:
Selection.Find(What:=DatePlusOne, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

DateNotFound:

MsgBox "All OK"

End Sub

--
Thank you very much for your help. Suggestions and work-arounds will be
greatly appreciated. May you have a most blessed day!

Sincerely,

Michael Fitzpatrick
 
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
Find and Replace - delete the remainder of the text in the cell after my Find [email protected] Excel Programming 4 August 4th 07 03:39 AM
Despite data existing in Excel 2002 spreadsheet Find doesn't find AnnieB Excel Discussion (Misc queries) 1 June 16th 06 02:15 AM
Find method fails in hidden range Rick Hansen Excel Programming 2 April 6th 06 10:54 PM
find and delete duplicate entries in two columns or find and prin. campare 2 columns of numbers-find unique Excel Programming 1 November 24th 04 04:09 PM
Find instruction fails (from foreign sheet) Kinne Excel Programming 2 August 11th 03 01:48 PM


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