Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Help with FindNext Method

I have the following code which is searching through a coloumn of data
looking for a number when it finds it, it crosses checks it with a date
if its the one i'm looking for I store it and continue searching for
the next entry. but it doesn't appear to find any values, when I step
through the code rFound = 'Nothing' and I can't work out why. any help
would be great.

Thanks

Dwight


'Find the all occurances of Notional
Dim rFound As Range
Dim sFirstAddress As String

'Set search range to column

Set rFound = ActiveSheet.Columns(Not_Col).Find(Notional)
'If Notional was found
If Not rFound Is Nothing Then
'Store the address in a variable
sFirstAddress = rFound.Address
'Start a loop
Do
row_temp = rFound.Row
Cust_M_Dt = ActiveSheet.Cells(row_temp, M_Dat_Col).Value

If M_Date = Cust_M_Date Then
If flag = 0 Then
Swp_Rw_1 = row_temp
flag = 1
End If

If flag = 1 Then
Swp_Rw_2 = row_temp
flag = 2
End If
End If

'Find the next cell with Notional
Set rFound = ActiveSheet.Columns(Not_Col).FindNext(rFound)
'Stop when Find loops back to the first cell found
Loop Until rFound.Address = sFirstAddress
End If

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Help with FindNext Method

Dewey,

A lot was missing from your code, but the example below worked for me, to find the number 4 in
column B where the date in column C is the current day's date. I wasn't sure what you were doing
with the flag, so I commented it out....

HTH,
Bernie
MS Excel MVP

Sub TryNow()
'Find the all occurances of Notional (4) in column B
'that have today's date in column C
Dim rFound As Range
Dim sFirstAddress As String
Dim Notional As Integer
Dim M_Dat_Col As Integer
Dim Not_Col As Integer
Dim row_temp As Long
Dim Cust_M_Date As Date
Dim M_Date As Date

Notional = 4
Not_Col = 2
M_Dat_Col = 3
M_Date = Int(Now)

'Set search range to column

Set rFound = ActiveSheet.Columns(Not_Col).Find(Notional)
'If Notional was found
If Not rFound Is Nothing Then
'Store the address in a variable
sFirstAddress = rFound.Address
'Start a loop
Do
row_temp = rFound.Row
Cust_M_Date = ActiveSheet.Cells(row_temp, M_Dat_Col).Value

If M_Date = Cust_M_Date Then
' If flag = 0 Then
' Swp_Rw_1 = row_temp
' flag = 1
' End If
'
' If flag = 1 Then
' Swp_Rw_2 = row_temp
' flag = 2
' End If

MsgBox "I found a match in row " & row_temp
End If

'Find the next cell with Notional
Set rFound = ActiveSheet.Columns(Not_Col).FindNext(rFound)
'Stop when Find loops back to the first cell found
Loop Until rFound.Address = sFirstAddress
End If

End Sub




"Dewey" wrote in message
oups.com...
I have the following code which is searching through a coloumn of data
looking for a number when it finds it, it crosses checks it with a date
if its the one i'm looking for I store it and continue searching for
the next entry. but it doesn't appear to find any values, when I step
through the code rFound = 'Nothing' and I can't work out why. any help
would be great.

Thanks

Dwight


'Find the all occurances of Notional
Dim rFound As Range
Dim sFirstAddress As String

'Set search range to column

Set rFound = ActiveSheet.Columns(Not_Col).Find(Notional)
'If Notional was found
If Not rFound Is Nothing Then
'Store the address in a variable
sFirstAddress = rFound.Address
'Start a loop
Do
row_temp = rFound.Row
Cust_M_Dt = ActiveSheet.Cells(row_temp, M_Dat_Col).Value

If M_Date = Cust_M_Date Then
If flag = 0 Then
Swp_Rw_1 = row_temp
flag = 1
End If

If flag = 1 Then
Swp_Rw_2 = row_temp
flag = 2
End If
End If

'Find the next cell with Notional
Set rFound = ActiveSheet.Columns(Not_Col).FindNext(rFound)
'Stop when Find loops back to the first cell found
Loop Until rFound.Address = sFirstAddress
End If



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
Findnext Noemi Excel Discussion (Misc queries) 1 December 12th 05 11:23 AM
Can .FindNext return Nothing?? Wild Bill[_2_] Excel Programming 22 April 30th 05 07:51 PM
FindNext John Keturi Excel Programming 1 October 16th 04 01:56 PM
FindNext SJ[_6_] Excel Programming 7 May 21st 04 06:01 AM
findnext issues mark kubicki Excel Programming 3 February 15th 04 03:22 AM


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