ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find method - finding multiple values (https://www.excelbanter.com/excel-programming/338084-find-method-finding-multiple-values.html)

Nathan

Find method - finding multiple values
 
Is there simple way to use "find" to search for more than one string? i.e.
find "b" or find "s", without running separate a "find" code for each string.
this doesn't work, but explains what I want to do: .find(what:="b" or "s")

thanks again.

Jim Thomlinson[_4_]

Find method - finding multiple values
 
Nope and there would be no real point to it. The find function finding all
instances of B and then finding all of the instances of S would be the same
as finding all of the instaces of B or S. It would not be any more efficient
one way or the other becuase the find has to do the exact same amount of work
finding all instances of B and all instance of S.
--
HTH...

Jim Thomlinson


"nathan" wrote:

Is there simple way to use "find" to search for more than one string? i.e.
find "b" or find "s", without running separate a "find" code for each string.
this doesn't work, but explains what I want to do: .find(what:="b" or "s")

thanks again.


Tom Ogilvy

Find method - finding multiple values
 
no. But then how hard is it to put the strings in an array and loop through
the strings?

Regards,
Tom Ogilvy

"nathan" wrote in message
...
Is there simple way to use "find" to search for more than one string?

i.e.
find "b" or find "s", without running separate a "find" code for each

string.
this doesn't work, but explains what I want to do: .find(what:="b" or

"s")

thanks again.




John

Find method - finding multiple values
 
Nathan

try something like this...

Dim rngToSearch As Range
Dim wks As Worksheet
Dim rngFound As Range
Dim WhatToFind As Variant
Dim iCtr As Long
Dim DestCell As Range

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Set wks = Sheets("sheetname")
Set rngToSearch = wks.Columns(6)

WhatToFind = Array("1", "2", "3")

For iCtr = LBound(WhatToFind) To UBound(WhatToFind)
With rngToSearch
Set rngFound = .Cells.Find(what:=WhatToFind(iCtr), _
LookIn:=xlValues, lookat:=xlWhole, _
after:=.Cells(.Cells.Count), _
MatchCase:=False)
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic


"nathan" wrote:

Is there simple way to use "find" to search for more than one string? i.e.
find "b" or find "s", without running separate a "find" code for each string.
this doesn't work, but explains what I want to do: .find(what:="b" or "s")

thanks again.


Nathan

Find method - finding multiple values
 
if that is a way to do it, then that is what I am looking for help on. looks
like john showed an example of that. thanks.

"Tom Ogilvy" wrote:

no. But then how hard is it to put the strings in an array and loop through
the strings?

Regards,
Tom Ogilvy

"nathan" wrote in message
...
Is there simple way to use "find" to search for more than one string?

i.e.
find "b" or find "s", without running separate a "find" code for each

string.
this doesn't work, but explains what I want to do: .find(what:="b" or

"s")

thanks again.





Nathan

Find method - finding multiple values
 
I'm trying to keep the code writing effecient, clear and down to a minimum.
thanks.

"Jim Thomlinson" wrote:

Nope and there would be no real point to it. The find function finding all
instances of B and then finding all of the instances of S would be the same
as finding all of the instaces of B or S. It would not be any more efficient
one way or the other becuase the find has to do the exact same amount of work
finding all instances of B and all instance of S.
--
HTH...

Jim Thomlinson


"nathan" wrote:

Is there simple way to use "find" to search for more than one string? i.e.
find "b" or find "s", without running separate a "find" code for each string.
this doesn't work, but explains what I want to do: .find(what:="b" or "s")

thanks again.


Nathan

Find method - finding multiple values
 
thanks.

"John" wrote:

Nathan

try something like this...

Dim rngToSearch As Range
Dim wks As Worksheet
Dim rngFound As Range
Dim WhatToFind As Variant
Dim iCtr As Long
Dim DestCell As Range

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Set wks = Sheets("sheetname")
Set rngToSearch = wks.Columns(6)

WhatToFind = Array("1", "2", "3")

For iCtr = LBound(WhatToFind) To UBound(WhatToFind)
With rngToSearch
Set rngFound = .Cells.Find(what:=WhatToFind(iCtr), _
LookIn:=xlValues, lookat:=xlWhole, _
after:=.Cells(.Cells.Count), _
MatchCase:=False)
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic


"nathan" wrote:

Is there simple way to use "find" to search for more than one string? i.e.
find "b" or find "s", without running separate a "find" code for each string.
this doesn't work, but explains what I want to do: .find(what:="b" or "s")

thanks again.



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

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