M
MichaelDavid
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
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