Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Limit search range then loop thru' each cell...a bit stuck...

Hello there...

I have this code so far..

Sub findnumber5()
Sheets("Data sheet").Range("P2").Select
Do Until ActiveCell.Value = ActiveSheet.Range("R20").Value
ActiveCell.Offset(1, 0).Select
Loop
ActiveSheet.Range("S13").Value = ActiveCell.Row - 1
'the range needs to be P2:activesheet.value("S28")+1
End Sub

I need to find the very first occurence of the number 5, but the code
will
search all 65000 rows whereas I only need to seach: thru
P2:activesheet.value"S28")+1 ... and what if the number 5 is not
there?
it will need to exit..any help would be greatly appreciated...

ste
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Limit search range then loop thru' each cell...a bit stuck...

Dim lastrow as Long, rng as Long, rng1 as Long
lastrow = Activesheet.Range("S28").Value + 1
set rng = Range("P2:P" & LastRow)
set rng1 = rng.Find(Range("R20").Value)
if not rng1 is nothing then
msgbox "Found at " & rng1.Address
else
msgbox "Not found"
End if

--
Regards,
Tom Ogilvy


"ste mac" wrote in message
om...
Hello there...

I have this code so far..

Sub findnumber5()
Sheets("Data sheet").Range("P2").Select
Do Until ActiveCell.Value = ActiveSheet.Range("R20").Value
ActiveCell.Offset(1, 0).Select
Loop
ActiveSheet.Range("S13").Value = ActiveCell.Row - 1
'the range needs to be P2:activesheet.value("S28")+1
End Sub

I need to find the very first occurence of the number 5, but the code
will
search all 65000 rows whereas I only need to seach: thru
P2:activesheet.value"S28")+1 ... and what if the number 5 is not
there?
it will need to exit..any help would be greatly appreciated...

ste



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
stuck in an error loop Darla Excel Discussion (Misc queries) 1 January 8th 10 06:06 PM
Stuck in a Sub Loop robzrob Excel Worksheet Functions 4 July 19th 08 11:53 PM
Excel with game is stuck in a loop [email protected] Excel Discussion (Misc queries) 2 December 19th 06 08:11 PM
Stuck in a loop CWillis Excel Discussion (Misc queries) 2 June 5th 06 02:49 PM
Excel 97 stuck in calculation loop - maximum cells problem? dl Excel Programming 1 June 25th 04 06:24 PM


All times are GMT +1. The time now is 12:17 AM.

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"