LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
jon jon is offline
external usenet poster
 
Posts: 18
Default Damn error 91!

OK you intelligent people, could you help me with this
simple bit of code.

It needs to search down from A1 to find the first
occurance of "c" for example, the search from the bottom
of column a to find the last one (all the "c"'s will be
continuous).

It works fine, unless one of the strings isn't in the
list, in which case it comes up with a run time error 91.

is there a condition i can put in for if the search
doesn't find anything, or alternatively, how do you use
findfirst and findlast functions?

All help very much appreciated,

TIA


The Code...


For a = 1 To 6

If a = 1 Then district = "A"
If a = 2 Then district = "B"
If a = 3 Then district = "C"
If a = 4 Then district = "D"
If a = 5 Then district = "E"
If a = 6 Then district = "F"

Range("A65000").End(xlUp).Select
n = ActiveCell.Row
Range("A1", "A" & n).Select

Selection.Find(What:=district, After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
frst = ActiveCell.Row

Range("A" & n + 2).Select
Selection.Find(What:=district, After:=ActiveCell,
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:=xlPrevious, MatchCase:= _
False, SearchFormat:=False).Select
lst = ActiveCell.Row

Range("A" & frst, "A" & lst).Select
Selection.EntireRow.Select

Selection.Copy
cgc.Activate
Range("A65000").End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste

Next a
 
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
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
Counting instances of found text (Excel error? Or user error?) S Davis Excel Worksheet Functions 5 September 12th 06 04:52 PM
DateDif Average? Damn DateDif UTCHELP Excel Worksheet Functions 14 November 17th 05 10:30 AM
Get excel 2005 to line up damn dollar signs properly. Idiots. DGWeeks Excel Discussion (Misc queries) 1 September 15th 05 06:51 AM


All times are GMT +1. The time now is 07:06 AM.

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"