View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Finding an exact string in a range

Hi,

In the sample code below "18" is a string but Excel is very forgiving and 18
could be a number. Anyway, having found it you don't say what you want to do
so this just gives the address in a message box

Dim Start_Rng As Range
Dim Curr_DU As Long
Curr_DU = "18"
Set Start_Rng = Range("C2:C50")
For Each c In Start_Rng
If c.Value = Curr_DU Then
'do something
MsgBox c.Address
End If
Next

Mike

"Planner999" wrote:

Hi all

I really need some help please....

I have list of values in a range of cells

18A
18B
18C
18D
18E
18

There is a string variable called Curr_DU

The line of code reads

Dim Start_Rng as Range
Dim Curr_DU as String


Set Start_Rng = Range ("C2:C50").Find(Curr_DU)

This works great until it hits the last value which is 18 but it then
picks up 18A position. How can I simply change the macro to be
specific on finding 18 but not the others.

Thanks in Advance

John