Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Run-time error '91': "Object variable or With block variable not set

Run-time error '91': "Object variable or With block variable not set in
the following code" occurs on the following line:

..Find(What:="*/*/04", After:=ActiveCell, LookIn:=xlValues,
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False).Activate

I don't know why...can someone help??? The code is shown below.

Thanks In Advance,
Mike Taylor

Option Explicit

Sub TestCopyTo2005()
Dim rDest As Range
Dim rSource As Range
Dim Ssh As Worksheet
Dim Dsh As Worksheet

Set Ssh = ThisWorkbook.Sheets("Revenue-Client Data Entry")
Set Dsh = Workbooks("2005.xls").Sheets("Revenue-Client Data Entry")

With Workbooks("2004.xls").Worksheets("Revenue-Client Data
Entry").Range("B4:AJ305")
..Select
..Sort Key1:=Range("B4"), _
Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, _ Orientation:=xlTopToBottom

'Code errors on the following line:
..Find(What:="*/*/04", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate

End With

Set rSource = Range(ActiveCell, Range("AJ305"))
Set rDest = Workbooks("2005.xls").Sheets("Revenue-Client Data _
Entry").Range("B4")

rSource.Copy rDest

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Run-time error '91': "Object variable or With block variable not set

Mike,

I think the error occurs when not found. Try

Dim rDest As Range
Dim rSource As Range
Dim Ssh As Worksheet
Dim Dsh As Worksheet
Dim oCell As Range

Set Ssh = ThisWorkbook.Sheets("Revenue-Client Data Entry")
Set Dsh = Workbooks("2005.xls").Sheets("Revenue-Client Data Entry")

With Ssh.Range("B4:AJ305") 'Workbooks("2004.xls").Worksheets("Revenue-Client
Data Entry").Range("B4:AJ305")
.Select
.Sort Key1:=Range("B4"), _
Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom

'Code errors on the following line:
On Error Resume Next
.Find(What:="/04", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate

End With

Set rSource = Range(ActiveCell, Range("AJ305"))
Set rDest = Workbooks("2005.xls").Sheets("Revenue-Client Data
Entry").Range("B4")

rSource.Copy rDest

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mike" wrote in message
oups.com...
Run-time error '91': "Object variable or With block variable not set in
the following code" occurs on the following line:

.Find(What:="*/*/04", After:=ActiveCell, LookIn:=xlValues,
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False).Activate

I don't know why...can someone help??? The code is shown below.

Thanks In Advance,
Mike Taylor

Option Explicit

Sub TestCopyTo2005()
Dim rDest As Range
Dim rSource As Range
Dim Ssh As Worksheet
Dim Dsh As Worksheet

Set Ssh = ThisWorkbook.Sheets("Revenue-Client Data Entry")
Set Dsh = Workbooks("2005.xls").Sheets("Revenue-Client Data Entry")

With Workbooks("2004.xls").Worksheets("Revenue-Client Data
Entry").Range("B4:AJ305")
.Select
.Sort Key1:=Range("B4"), _
Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, _ Orientation:=xlTopToBottom

'Code errors on the following line:
.Find(What:="*/*/04", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate

End With

Set rSource = Range(ActiveCell, Range("AJ305"))
Set rDest = Workbooks("2005.xls").Sheets("Revenue-Client Data _
Entry").Range("B4")

rSource.Copy rDest

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 123
Default Run-time error '91': "Object variable or With block variable not set

If .Find result is nothing then it will give that error, because of the
last .Activate part. If no match is found it is not referring to any
cell, so .Active for nothing will give that error.

Change the code as under & try:

Dim myRange As Range
Set myRange = .Find(What:="*/*/2004", After:=ActiveCell,
LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)
If Not myRange Is Nothing Then myRange.Activate

Sharad



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
Error 91 -- Object variable or With block variable not set Rachael[_3_] Excel Programming 2 November 22nd 04 02:59 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 10:25 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"