PC Review


Reply
Thread Tools Rate Thread

Checking for duplicates

 
 
The Inspector
Guest
Posts: n/a
 
      28th Jun 2009

I have a macro that takes data (name, month, amount etc..) from one worksheet
and enters it into a table on another sheet. What I want is a message box to
ask the user if he/she is sure the data needs to be entered if the name to be
entered in the name column of the table would create a duplicate in that
column, as a duplicate entry would be rare. The more likely senario would be
that the user entered the wrong month in the first sheet and needs to correct
it.
Any help is greatly appreciated.
 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      28th Jun 2009

Something like the below...Change the <entername> to a name string or cell
reference. ws1 in the below example is Sheet2. Adjust to suit. The below code
checks whether the name already exists in Sheet2 Column A. If exists the
procedure exists. or otherwise will continue

Sub Macro
Dim ws1 As Worksheet
Set ws1 = ActiveWorkbook.Sheets("Sheet2")

If WorksheetFunction.CountIf(ws1.Range("A:A"), "<entername>") > 0 Then
If MsgBox("This name already exists. Are you sure to copy ?", vbYesNo + _
vbQuestion + vbDefaultButton2) <> vbYes Then Exit Sub
End If

'Your code to copy continue here

End Sub

If this post helps click Yes
---------------
Jacob Skaria


"The Inspector" wrote:

> I have a macro that takes data (name, month, amount etc..) from one worksheet
> and enters it into a table on another sheet. What I want is a message box to
> ask the user if he/she is sure the data needs to be entered if the name to be
> entered in the name column of the table would create a duplicate in that
> column, as a duplicate entry would be rare. The more likely senario would be
> that the user entered the wrong month in the first sheet and needs to correct
> it.
> Any help is greatly appreciated.

 
Reply With Quote
 
Bernd P
Guest
Posts: n/a
 
      28th Jun 2009
Hello,

A worksheet function countif approach is suboptimal if you need to
check a large amount of data. Please see an analysis of an analogous
case:
http://www.sulprobil.com/html/count_unique.html

I would suggest some code fragment similar to my UDFs Pstat or Pfreq:
http://www.sulprobil.com/html/pstat.html
http://www.sulprobil.com/html/pfreq.html

Regards,
Bernd


 
Reply With Quote
 
The Inspector
Guest
Posts: n/a
 
      28th Jun 2009

Thanks.
If WorksheetFunction.CountIf(ws1.Range("A:A"), "<entername>") > 0
"Jacob Skaria" wrote:

> Something like the below...Change the <entername> to a name string or cell
> reference. ws1 in the below example is Sheet2. Adjust to suit. The below code
> checks whether the name already exists in Sheet2 Column A. If exists the
> procedure exists. or otherwise will continue
>
> Sub Macro
> Dim ws1 As Worksheet
> Set ws1 = ActiveWorkbook.Sheets("Sheet2")
>
> If WorksheetFunction.CountIf(ws1.Range("A:A"), "<entername>") > 0 Then
> If MsgBox("This name already exists. Are you sure to copy ?", vbYesNo + _
> vbQuestion + vbDefaultButton2) <> vbYes Then Exit Sub
> End If
>
> 'Your code to copy continue here
>
> End Sub
>
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "The Inspector" wrote:
>
> > I have a macro that takes data (name, month, amount etc..) from one worksheet
> > and enters it into a table on another sheet. What I want is a message box to
> > ask the user if he/she is sure the data needs to be entered if the name to be
> > entered in the name column of the table would create a duplicate in that
> > column, as a duplicate entry would be rare. The more likely senario would be
> > that the user entered the wrong month in the first sheet and needs to correct
> > it.
> > Any help is greatly appreciated.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking for duplicates RAYCV Microsoft Excel Programming 2 23rd Sep 2008 04:48 PM
Checking for duplicates. =?Utf-8?B?Q3liZXJ3b2xm?= Microsoft Access VBA Modules 4 12th Aug 2005 11:55 AM
Checking for duplicates: VBA Jim Microsoft Excel Programming 4 2nd Dec 2004 01:22 PM
checking for duplicates Soondaram Microsoft Excel Discussion 1 27th Feb 2004 11:25 AM
Checking for Duplicates Axim5 Microsoft Excel Discussion 2 19th Oct 2003 01:30 PM


Features
 

Advertising
 

Newsgroups
 


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