Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Another Error 91 question!?

Keep getting the same error when I can't find the text. Basically, I have
the code doing exactly what I want when I find "final summary". That is,
deleting everything from "final summary" down. But when it doesnt find it, I
get the error. I looked here and tried some of the ways w/ setting the
range. When it didn't find it, it worked great. But when it did find it, it
doesn't do what I wanted it to do. Here is the code that works fine when it
finds "final summary" and errors when not:

Cells.Find(what:="final summary", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.ClearContents

But, I can't get it to work when I try the range method. So, the code above
works fine when it finds "final summary" and errors when not. And the range
method works fine when it doesn't find "final summary", but doesn't delete
"final summary" and everthing below it. Any ideas/suggestions?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Another Error 91 question!?

Dim rng as Range
set rng = Cells.Find(what:="final summary", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
if not rng is nothing then
rng.Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.ClearContents
else
msgbox "final summary not found"
End if

--
Regards,
Tom Ogilvy


"escudolm" wrote in message
...
Keep getting the same error when I can't find the text. Basically, I have
the code doing exactly what I want when I find "final summary". That is,
deleting everything from "final summary" down. But when it doesnt find

it, I
get the error. I looked here and tried some of the ways w/ setting the
range. When it didn't find it, it worked great. But when it did find it,

it
doesn't do what I wanted it to do. Here is the code that works fine when

it
finds "final summary" and errors when not:

Cells.Find(what:="final summary", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.ClearContents

But, I can't get it to work when I try the range method. So, the code

above
works fine when it finds "final summary" and errors when not. And the

range
method works fine when it doesn't find "final summary", but doesn't delete
"final summary" and everthing below it. Any ideas/suggestions?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Another Error 91 question!?

When writing code using Find, it is best to structure the code as
follows:

Dim FoundCell As Range
Set FoundCell = Cells.Find(...)
If FoundCell Is Nothing Then
' not found
Else
FoundCell.Select
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"escudolm" wrote in message
...
Keep getting the same error when I can't find the text.
Basically, I have
the code doing exactly what I want when I find "final summary".
That is,
deleting everything from "final summary" down. But when it
doesnt find it, I
get the error. I looked here and tried some of the ways w/
setting the
range. When it didn't find it, it worked great. But when it
did find it, it
doesn't do what I wanted it to do. Here is the code that works
fine when it
finds "final summary" and errors when not:

Cells.Find(what:="final summary", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.ClearContents

But, I can't get it to work when I try the range method. So,
the code above
works fine when it finds "final summary" and errors when not.
And the range
method works fine when it doesn't find "final summary", but
doesn't delete
"final summary" and everthing below it. Any ideas/suggestions?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Another Error 91 question!?

Thanks for the help. I'll see if it works.
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
#VALUE ERROR Question Brent Excel Discussion (Misc queries) 1 May 13th 10 12:32 AM
Error msg question April Excel Discussion (Misc queries) 4 October 14th 06 08:37 PM
#Ref error question TimN Excel Worksheet Functions 2 July 31st 06 02:31 PM
'On Error' question GEB Excel Programming 1 June 29th 05 08:49 PM
Drillthrough MDX ERROR(Error.Number:-21467259) ?(urgent question) Microlong Excel Programming 2 March 4th 05 01:55 AM


All times are GMT +1. The time now is 11:14 PM.

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"