Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Ensure items in a list aren't entered twice

Hi

I am using a user form so that users can enter a new customer into a
small program I am creating. I want to ensure that if the customer
already exists that it doesn't get added again. The code I have
created is as follows:
' ************ ADD CODE TO CHECK IF THE CUSTOMER IS ALREADY EXISTING
********
' IF EXISTING DISPLAY MSGBOX "CUTOMER ALREADY EXISTS, PLEASE PRESS
CANCEL AND LOOKUP THE CUSTOMER CODE"
'================================================= ===============
Sheets("CompanyList").Select
Range("C:C").Select

Set rngFound = Selection.Find(What:=CompanyNameEnglish,
After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False)

If rngFound.Value = CompanyNameEnglish Then
MsgBox "Customer already exists, please lookup customer
code"

This works if the customer already is in the list and the msgbox is
displayed. However, when a new customer is entered the program will
not pass the line with the set comand. I have looked through the help
file and found that the sytanx should include " | Nothing" at the end
of the set statement to clear the rngFound.

However, when the program runs it states that "|" is an invalid
characer.

How can I get the set method to blank if the item is not found so the
rest of the program can continue?

Thank,

Martin

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default Ensure items in a list aren't entered twice

On 16 Aug, 11:55, "
wrote:
Hi

I am using a user form so that users can enter a new customer into a
small program I am creating. I want to ensure that if the customer
already exists that it doesn't get added again. The code I have
created is as follows:
' ************ ADD CODE TO CHECK IF THE CUSTOMER IS ALREADY EXISTING
********
' IF EXISTING DISPLAY MSGBOX "CUTOMER ALREADY EXISTS, PLEASE PRESS
CANCEL AND LOOKUP THE CUSTOMER CODE"
'================================================= ===============
Sheets("CompanyList").Select
Range("C:C").Select

Set rngFound = Selection.Find(What:=CompanyNameEnglish,
After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False)

If rngFound.Value = CompanyNameEnglish Then
MsgBox "Customer already exists, please lookup customer
code"

This works if the customer already is in the list and the msgbox is
displayed. However, when a new customer is entered the program will
not pass the line with the set comand. I have looked through the help
file and found that the sytanx should include " | Nothing" at the end
of the set statement to clear the rngFound.

However, when the program runs it states that "|" is an invalid
characer.

How can I get the set method to blank if the item is not found so the
rest of the program can continue?

Thank,

Martin


Why worry about the find command at all - why not use the
worksheetfunction.countif command - this will count the number of
instances - if it's zero, new customer, else look up code (which by
the way you could code in as well, rather than getting the user to
make the correction)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 182
Default Ensure items in a list aren't entered twice

Martin,

Try to replace your code:
If rngFound.Value = CompanyNameEnglish Then
MsgBox "Customer already exists, please lookup customer"
End If

to:

If Not rngFound Is Nothing Then
If rngFound.Value = CompanyNameEnglish Then
MsgBox "Customer already exists, please lookup customer"
End If
End If

''''Not rngFound Is Nothing is to do If rngFound.Value while found, _
if not found there error occured, cause of empty object assignment


--
Regards,

Halim



" wrote:

Hi

I am using a user form so that users can enter a new customer into a
small program I am creating. I want to ensure that if the customer
already exists that it doesn't get added again. The code I have
created is as follows:
' ************ ADD CODE TO CHECK IF THE CUSTOMER IS ALREADY EXISTING
********
' IF EXISTING DISPLAY MSGBOX "CUTOMER ALREADY EXISTS, PLEASE PRESS
CANCEL AND LOOKUP THE CUSTOMER CODE"
'================================================= ===============
Sheets("CompanyList").Select
Range("C:C").Select

Set rngFound = Selection.Find(What:=CompanyNameEnglish,
After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False)

If rngFound.Value = CompanyNameEnglish Then
MsgBox "Customer already exists, please lookup customer
code"

This works if the customer already is in the list and the msgbox is
displayed. However, when a new customer is entered the program will
not pass the line with the set comand. I have looked through the help
file and found that the sytanx should include " | Nothing" at the end
of the set statement to clear the rngFound.

However, when the program runs it states that "|" is an invalid
characer.

How can I get the set method to blank if the item is not found so the
rest of the program can continue?

Thank,

Martin


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ensure data entered where required - how, please? Edward[_4_] Excel Discussion (Misc queries) 3 September 28th 09 02:02 PM
can I ensure a drop down list is used i.e by preventing printing Have a Go Excel Discussion (Misc queries) 1 December 15th 06 04:27 AM
Data Validation: items in one list relate to items in another Paul D. Simon Excel Programming 1 August 4th 05 09:17 PM
named range, data validation: list non-selected items, and new added items KR Excel Discussion (Misc queries) 1 June 24th 05 05:21 AM
Items in disabled items list - unknown excel addins causing probs Rich Excel Programming 4 May 16th 05 10:31 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"