ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Search for text value in range (https://www.excelbanter.com/excel-programming/355574-search-text-value-range.html)

tig

Search for text value in range
 
I'm looking for an efficient method to search for a text value. I have
a named range. Let's say range = A7:A14. I want to check cells C7:C14
to find the first cell whose value matches a previously populated
variable. It's possible that none of the cells have that value in it.

It seems that I could use a for all loop but I can't seem to get the
syntax right. I've already got a ton of named ranges. I'm trying to
avoid setting up a bunch more.

Any ideas??

TIA


Rick Hansen

Search for text value in range
 
Tig, I don't know if this is what your looking for, but give this code a
shot.

hth , Rick


Sub FindDup()
Dim dupRng As Range, fndRng As Range
Dim x As Long


Set dupRng = Range("A7:A14")
x = 7 '' start row
Do Until IsEmpty(Cells(x, "C").Value)
Set fndRng = dupRng.Find(what:=Cells(x, "C").Value)
If Not fndRng Is Nothing Then
MsgBox ("Duplicate Found at = " & fndRng.Address)
Exit Sub
End If
x = x + 1
Loop

MsgBox ("No Duplicates Found")

End Sub




"tig" wrote in message
oups.com...
I'm looking for an efficient method to search for a text value. I have
a named range. Let's say range = A7:A14. I want to check cells C7:C14
to find the first cell whose value matches a previously populated
variable. It's possible that none of the cells have that value in it.

It seems that I could use a for all loop but I can't seem to get the
syntax right. I've already got a ton of named ranges. I'm trying to
avoid setting up a bunch more.

Any ideas??

TIA





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

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