ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   two consescutive finds (https://www.excelbanter.com/excel-programming/340467-two-consescutive-finds.html)

R.VENKATARAMAN

two consescutive finds
 
recently while trying to find solution I have to configure two consecutive
finds. further on when i want to do findnext of the first find the programme
did findnext of only the second find and not the first one (sorry the
question has become convolute).some extract and comments are given below
the entries data and data1 are interspersed with some other data and the
entries data and data1 are repeated.


the code is something like this
Dim cellsfind As Range
Dim cellsfind1 As Range
Set cellsfind = Cells.Find("data", lookat:=xlWhole)
MsgBox cellsfind 'it is <data
Set cellsfind1 = Cells.Find("data1", lookat:=xlWhole)
MsgBox cellsfind1 'it is <data1
cellsfind1.Select
Set cellsfind = Cells.FindNext(cellsfind)
MsgBox cellsfind 'it is again data1 and not data which I thought it should
be as I used <cellsfind variable
code ends
where do I do the mistake.
ofcourse i solved the problem by a pedestrian and inelegant method of after
the first set of finds looping the same <find codes till the loop reaches
the end of the range (without using find next)

thanks and regards.






Tom Ogilvy

two consescutive finds
 
Dim cellsfind As Range
Dim cellsfind1 As Range
MsgBox cellsfind 'it is <data
Set cellsfind1 = Cells.Find("data1", lookat:=xlWhole)
MsgBox cellsfind1 'it is <data1
cellsfind1.Select
Set cellsfind = Cells.Find("data", After:CellsFind,lookat:=xlWhole)


FindNext refers to the last find executed.

--
Regards,
Tom Ogilvy


"R.VENKATARAMAN" wrote in message
...
recently while trying to find solution I have to configure two consecutive
finds. further on when i want to do findnext of the first find the

programme
did findnext of only the second find and not the first one (sorry the
question has become convolute).some extract and comments are given below
the entries data and data1 are interspersed with some other data and the
entries data and data1 are repeated.


the code is something like this
Dim cellsfind As Range
Dim cellsfind1 As Range
Set cellsfind = Cells.Find("data", lookat:=xlWhole)
MsgBox cellsfind 'it is <data
Set cellsfind1 = Cells.Find("data1", lookat:=xlWhole)
MsgBox cellsfind1 'it is <data1
cellsfind1.Select
Set cellsfind = Cells.FindNext(cellsfind)
MsgBox cellsfind 'it is again data1 and not data which I thought it

should
be as I used <cellsfind variable
code ends
where do I do the mistake.
ofcourse i solved the problem by a pedestrian and inelegant method of

after
the first set of finds looping the same <find codes till the loop reaches
the end of the range (without using find next)

thanks and regards.








R.VENKATARAMAN

two consescutive finds
 
thank you. But I apologise I did not explain properly. the range contains
data and data1 repeatedl;y;
I want to find both data and data1 succesively to find out the number of
intervening cells in each set and then take some action
my inelegant sub is like this (I did not use findnext)

Public Sub test()
Range("a1").Activate
Dim i As Integer
Dim j As Integer
Dim add1
Cells.Find("data", lookat:=xlWhole, after:=ActiveCell).Activate
add1 = ActiveCell.Address
MsgBox add1
Cells.Find("data1", lookat:=xlWhole, after:=ActiveCell).Activate
MsgBox ActiveCell.Address
Do
Cells.Find("data", lookat:=xlWhole, after:=ActiveCell).Activate
If ActiveCell.Address = add1 Then Exit Sub
MsgBox ActiveCell.Address
Cells.Find("data1", lookat:=xlWhole, after:=ActiveCell).Activate
MsgBox ActiveCell.Address
Loop
End Sub

regards





r.venkataraman
==============
"Tom Ogilvy" wrote in message
...
Dim cellsfind As Range
Dim cellsfind1 As Range
MsgBox cellsfind 'it is <data
Set cellsfind1 = Cells.Find("data1", lookat:=xlWhole)
MsgBox cellsfind1 'it is <data1
cellsfind1.Select
Set cellsfind = Cells.Find("data", After:CellsFind,lookat:=xlWhole)


FindNext refers to the last find executed.

--
Regards,
Tom Ogilvy


"R.VENKATARAMAN" wrote in message
...
recently while trying to find solution I have to configure two

consecutive
finds. further on when i want to do findnext of the first find the

programme
did findnext of only the second find and not the first one (sorry the
question has become convolute).some extract and comments are given below
the entries data and data1 are interspersed with some other data and the
entries data and data1 are repeated.


the code is something like this
Dim cellsfind As Range
Dim cellsfind1 As Range
Set cellsfind = Cells.Find("data", lookat:=xlWhole)
MsgBox cellsfind 'it is <data
Set cellsfind1 = Cells.Find("data1", lookat:=xlWhole)
MsgBox cellsfind1 'it is <data1
cellsfind1.Select
Set cellsfind = Cells.FindNext(cellsfind)
MsgBox cellsfind 'it is again data1 and not data which I thought it

should
be as I used <cellsfind variable
code ends
where do I do the mistake.
ofcourse i solved the problem by a pedestrian and inelegant method of

after
the first set of finds looping the same <find codes till the loop

reaches
the end of the range (without using find next)

thanks and regards.













All times are GMT +1. The time now is 11:58 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com