Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Damn error 91!

Jon,

Generally, when you are using Find, you should write your code
similar to the following:

Dim FoundCell As Range
Set FoundCell = Cells.Find(....)
If Not FoundCell Is Nothing Then
' Find was successful, do something with FoundCell
Else
' Not Found
End If


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



"jon" wrote in message
...
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



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
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 04:36 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"