Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Using the FIND function in a loop

Hello,
I have two worksheet x and y.
x - Column C
1
2
3
4
5

y - Column C
1
1
2
3
2
1
1

I am trying to use the FIND function to traverse through y - Column C and
return the row value of the match in x - Column C to y - Column D.

Here is what I have so far. Note that it fails with the following message
for large record #'s: Code execution has been interrupted.

Dim rFound As Range

For i = 1 To 50000

Set rFound = Columns(3).Find(What:="" & Sheets("x").Cells(i, 3),
After:=Cells(2, 3), LookIn:=xlFormulas, LookAt:=xlWhole,
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False,
SearchFormat:=False)

Sheets("y").Cells(i,4) = rFound.Row

Next i

I think I may have reached some sort of system limitation.

Thanks in advance,
-Steve
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Using the FIND function in a loop

Edit: Made a typo..
What:="" & Sheets("x").Cells(i, 3)

should read as

What:="" & Sheets("y").Cells(i, 3)

"stevieb" wrote:

Hello,
I have two worksheet x and y.
x - Column C
1
2
3
4
5

y - Column C
1
1
2
3
2
1
1

I am trying to use the FIND function to traverse through y - Column C and
return the row value of the match in x - Column C to y - Column D.

Here is what I have so far. Note that it fails with the following message
for large record #'s: Code execution has been interrupted.

Dim rFound As Range

For i = 1 To 50000

Set rFound = Columns(3).Find(What:="" & Sheets("x").Cells(i, 3) ,
After:=Cells(2, 3), LookIn:=xlFormulas, LookAt:=xlWhole,
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False,
SearchFormat:=False)

Sheets("y").Cells(i,4) = rFound.Row

Next i

I think I may have reached some sort of system limitation.

Thanks in advance,
-Steve

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Using the FIND function in a loop

Edit #2: Problem solved.

i had to include a couple of lines of code that reset the FIND paramteres
before the enxt iteration.

Set rFound = Columns(3).Find("", LookIn:=xlValues, lookat:=xlWhole, _
searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=False)

Set rFound = Nothing

I know this is not optimal but it worked for the time being.

"stevieb" wrote:

Edit: Made a typo..
What:="" & Sheets("x").Cells(i, 3)

should read as

What:="" & Sheets("y").Cells(i, 3)

"stevieb" wrote:

Hello,
I have two worksheet x and y.
x - Column C
1
2
3
4
5

y - Column C
1
1
2
3
2
1
1

I am trying to use the FIND function to traverse through y - Column C and
return the row value of the match in x - Column C to y - Column D.

Here is what I have so far. Note that it fails with the following message
for large record #'s: Code execution has been interrupted.

Dim rFound As Range

For i = 1 To 50000

Set rFound = Columns(3).Find(What:="" & Sheets("x").Cells(i, 3) ,
After:=Cells(2, 3), LookIn:=xlFormulas, LookAt:=xlWhole,
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False,
SearchFormat:=False)

Sheets("y").Cells(i,4) = rFound.Row

Next i

I think I may have reached some sort of system limitation.

Thanks in advance,
-Steve

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
Do loop with find paularo Excel Programming 6 August 14th 09 03:31 PM
Find loop doesn't loop JSnow Excel Discussion (Misc queries) 2 June 24th 09 08:28 PM
Find Loop and then Loop again Don Guillett Excel Programming 0 December 7th 06 06:05 PM
Loops to find blanks then loop to find populated Bevy Excel Programming 0 June 1st 06 04:50 PM
Loop Function unable to loop Junior728 Excel Programming 1 July 28th 05 10:23 AM


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