Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find next problem

Search a range (column) for an items first apperance and last
apperance, the range is sorted.
There are roughly 100 unique items in the column, the column consits
of roughly 20 000 rows.
But if a given items passes row 99 or 999 or 9999 the code gives
answer that the end is these figures, even if the true range is from
row 85 to 115 etc. Why....?

......

Dim rngToSearch As Range
Dim rngFound As Range
Dim rngFoundAll As Range
Dim strFirst As String
Dim senaste As String
Dim slut As Integer
Dim först As Integer

Set rngToSearch = Worksheets("Basefile").Range("B2:B" & sista)

söka = cellg.Value ' find range that contains this item


Set rngFound = rngToSearch.Find(What:=söka, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
MatchCase:=False)
If Not rngFound Is Nothing Then
Set rngFoundAll = rngFound
strFirst = rngFound.Address
senaste= strFirst
Do
Set rngFoundAll = Union(rngFound, rngFoundAll)
Set rngFound = rngToSearch.FindNext(rngFound)
strlast = rngFound.Address
If Right(strlast, Len(strlast) - 3) Right(strFirst, Len
(strFirst) - 3) Then
senaste= strlast
End If
Loop Until rngFound.Address = strFirst

MsgBox strFirst & vbLf & vbLf & senaste ' will give the rows
to copy

End If

Hope for support...

BR

Jan Eric
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Find next problem

Hi Jan Eric,

I think this is what you need. Notice I added an "after" property to
the find statement.

Dim rngToSearch As Range
Dim rngFound As Range
Dim rngFoundAll As Range
Dim strFirst As String
Dim strLast As String
Dim senaste As String
Dim slut As Integer
Dim först As Integer

Set rngToSearch = Worksheets("Basefile").Range("B2:B" & sista)
Set LastCell = Worksheets("Basefile").Range("B" & sista)
söka = cellg.Value ' find range that contains this item
Set rngFound = rngToSearch.Find(What:=söka, _
After:=LastCell, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
MatchCase:=False)
If Not rngFound Is Nothing Then
Set rngFoundFirst = rngFound
Set rngFoundAll = rngFound
Do
Set rngFoundAll = Union(rngFound, rngFoundAll)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = rngFoundFirst.Address
MsgBox rngFirstFound.Row & vbLf & vbLf & rngFound.Row
'will give the rows to copy
End If

Regards,
Per

On 9 Aug., 17:44, Jan Eric Nilsson wrote:
Search a range (column) for an items first apperance and last
apperance, the range is sorted.
There are roughly 100 unique items in the column, the column consits
of roughly 20 000 rows.
But if a given items passes row 99 or 999 or 9999 the code gives
answer that the end is these figures, even if the true range is from
row 85 to 115 etc. Why....?

.....

* * Dim rngToSearch As Range
* * Dim rngFound As Range
* * Dim rngFoundAll As Range
* * Dim strFirst As String
* * Dim senaste As String
* * Dim slut As Integer
* * Dim först As Integer

Set rngToSearch = Worksheets("Basefile").Range("B2:B" & sista)

* * söka = cellg.Value * *' find range that contains this item

* * Set rngFound = rngToSearch.Find(What:=söka, _
* * * * * * * * * * * * * * * * * * LookIn:=xlValues, _
* * * * * * * * * * * * * * * * * * LookAt:=xlWhole, _
* * * * * * * * * * * * * * * * * * MatchCase:=False)
* * If Not rngFound Is Nothing Then
* * * * Set rngFoundAll = rngFound
* * * * strFirst = rngFound.Address
* * * * senaste= strFirst
* * * * Do
* * * * * * Set rngFoundAll = Union(rngFound, rngFoundAll)
* * * * * * Set rngFound = rngToSearch.FindNext(rngFound)
* * * * * * strlast = rngFound.Address
* * * * * * If Right(strlast, Len(strlast) - 3) Right(strFirst, Len
(strFirst) - 3) Then
* * * * * * * * senaste= strlast
* * * * * * End If
* * * * Loop Until rngFound.Address = strFirst

* * * * MsgBox strFirst & vbLf & vbLf & senaste *' will give the rows
to copy

* * *End If

Hope for support...

BR

Jan Eric


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
Problem with 'Find' Dave Excel Discussion (Misc queries) 5 December 15th 09 01:27 PM
Find problem Francis Hookham Excel Programming 5 May 31st 08 06:09 PM
Next without For? can't find the problem Ray Excel Programming 6 August 2nd 07 03:31 PM
Find and Find Next problem Richard Hocking Excel Programming 2 September 13th 06 03:51 PM
Problem with FIND LSB Excel Programming 2 January 12th 04 04:16 AM


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