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: 78
Default Error 91, Object var or With block not set

What am I doing wrong here?

I've searched this discussion group, and google groups, but can't find the
solution to the error, or an alternate way to code this. This code sorts the
worksheet by the dates in column B, then searches the cells in the column
looking for the last instance of myDate. (I need the address so I can select
a range and move it to another worksheet.) But I keep getting stuck with this
"Object var... not set" error.

If I'm missing something fundamental here, please point me in the right
direction. I've spent several hours looking for and trying alternate ways of
doing this, and researching setting object variables, but I keep ending up
back at the same error.

Private Sub btnDate_Click()
UserForm1.Hide
Range("A1:E261").Sort Key1:=Range("B1"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
If opt8.Value = True Then iDays = 9
If opt15.Value = True Then iDays = 16
If opt31.Value = True Then iDays = 32
'using "Set myDate = Date - iDays" gets error on next line
myDate = Date - iDays
'select column B to search in
Cells(1, 2).Activate
ActiveCell.End(xlDown).Select
strLast = Selection.Address
Set myRange = Range("B1", strLast)
'as written, error occurs on next line
myRange.Find(what:=myDate, lookat:=xlPart).Select
strLast = Selection.Address
Set myRange = Nothing
End Sub

Any help would be extremely appreciated!
 
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
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
Object or with block not set sidw0501 Excel Worksheet Functions 0 November 24th 08 07:27 PM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM
"Run-time error 91: Object variable or With block not set" Snedker Excel Programming 0 January 10th 04 09:37 AM
Error 91 - Object variable with block variable not set Jim[_35_] Excel Programming 2 November 27th 03 03:34 AM


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