close

I am trying to add names to a list which may contain names already. The
user enters the name in a box and then presses enter. I only want to
add a name to the list if it doesn't exists in the list already. This
is almost working, although the code seems to be picking up parts of
names already in the list. i.e. if I wanted to add the name quot;Annquot; to
the list, but the list already contains the name quot;Annabelquot; then it says
the name already exists. Can anyone help me so that it only says the
name exists in the list if it is an exact match...the code i have sol
far is below...........Thanks

Sub input_staff_name_checks()

staff_name = UCase(Cells(15, 9).Value)

If Len(staff_name) gt; 0 Then

Set rngLook = Worksheets(quot;Project Codes amp; Staff
Namesquot;).Range(quot;F5:F100quot;)

For j = 5 To 500

If staff_name lt;gt; Cells(j, 6).Value Then

Set rngFind = rngLook.Find(staff_name,
MatchCase:=True)

If rngFind Is Nothing Then
Call input_names *** this method here enters the
name in the list once the check has been done ***
Else
MsgBox (quot;Staff member's name is already on the
list!quot;)
End If

Set ringFind = Nothing
Exit For

End If

Next j

Else
MsgBox (quot;Please enter a staff member's namequot;)

End If

End Sub--
teeb
------------------------------------------------------------------------
teeb's Profile: www.excelforum.com/member.php...oamp;userid=13172
View this thread: www.excelforum.com/showthread...hreadid=539206Add LookAt:=xlWhole to the Find statement.

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

quot;teebquot; gt; wrote in message
...
gt;
gt; I am trying to add names to a list which may contain names already. The
gt; user enters the name in a box and then presses enter. I only want to
gt; add a name to the list if it doesn't exists in the list already. This
gt; is almost working, although the code seems to be picking up parts of
gt; names already in the list. i.e. if I wanted to add the name quot;Annquot; to
gt; the list, but the list already contains the name quot;Annabelquot; then it says
gt; the name already exists. Can anyone help me so that it only says the
gt; name exists in the list if it is an exact match...the code i have sol
gt; far is below...........Thanks
gt;
gt; Sub input_staff_name_checks()
gt;
gt; staff_name = UCase(Cells(15, 9).Value)
gt;
gt; If Len(staff_name) gt; 0 Then
gt;
gt; Set rngLook = Worksheets(quot;Project Codes amp; Staff
gt; Namesquot;).Range(quot;F5:F100quot;)
gt;
gt; For j = 5 To 500
gt;
gt; If staff_name lt;gt; Cells(j, 6).Value Then
gt;
gt; Set rngFind = rngLook.Find(staff_name,
gt; MatchCase:=True)
gt;
gt; If rngFind Is Nothing Then
gt; Call input_names *** this method here enters the
gt; name in the list once the check has been done ***
gt; Else
gt; MsgBox (quot;Staff member's name is already on the
gt; list!quot;)
gt; End If
gt;
gt; Set ringFind = Nothing
gt; Exit For
gt;
gt; End If
gt;
gt; Next j
gt;
gt; Else
gt; MsgBox (quot;Please enter a staff member's namequot;)
gt;
gt; End If
gt;
gt; End Sub
gt;
gt;
gt; --
gt; teeb
gt; ------------------------------------------------------------------------
gt; teeb's Profile:
www.excelforum.com/member.php...oamp;userid=13172
gt; View this thread: www.excelforum.com/showthread...hreadid=539206
gt;
Try this:

Set rngFind = rngLook.Find(staff_name, LookAt:=xlWhole,
MatchCase:=True)

Regards,
Stefi

?eeb??ezt ?rta:

gt;
gt; I am trying to add names to a list which may contain names already. The
gt; user enters the name in a box and then presses enter. I only want to
gt; add a name to the list if it doesn't exists in the list already. This
gt; is almost working, although the code seems to be picking up parts of
gt; names already in the list. i.e. if I wanted to add the name quot;Annquot; to
gt; the list, but the list already contains the name quot;Annabelquot; then it says
gt; the name already exists. Can anyone help me so that it only says the
gt; name exists in the list if it is an exact match...the code i have sol
gt; far is below...........Thanks
gt;
gt; Sub input_staff_name_checks()
gt;
gt; staff_name = UCase(Cells(15, 9).Value)
gt;
gt; If Len(staff_name) gt; 0 Then
gt;
gt; Set rngLook = Worksheets(quot;Project Codes amp; Staff
gt; Namesquot;).Range(quot;F5:F100quot;)
gt;
gt; For j = 5 To 500
gt;
gt; If staff_name lt;gt; Cells(j, 6).Value Then
gt;
gt; Set rngFind = rngLook.Find(staff_name,
gt; MatchCase:=True)
gt;
gt; If rngFind Is Nothing Then
gt; Call input_names *** this method here enters the
gt; name in the list once the check has been done ***
gt; Else
gt; MsgBox (quot;Staff member's name is already on the
gt; list!quot;)
gt; End If
gt;
gt; Set ringFind = Nothing
gt; Exit For
gt;
gt; End If
gt;
gt; Next j
gt;
gt; Else
gt; MsgBox (quot;Please enter a staff member's namequot;)
gt;
gt; End If
gt;
gt; End Sub
gt;
gt;
gt; --
gt; teeb
gt; ------------------------------------------------------------------------
gt; teeb's Profile: www.excelforum.com/member.php...oamp;userid=13172
gt; View this thread: www.excelforum.com/showthread...hreadid=539206
gt;
gt;

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()