Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA - Check for Duplicate Records

HI,

I have two worksheets "PV" & "Register".
PV form is to be completed & will be posted to Register when Use
executes the macro "PostToRegister".

I would like to check if the record being posted is a duplicate entry.

There are two cells named "Beneficiary" & "Amount" in the workshee
"PV" which I want to check against Cols "C" & "G" respectively i
worksheet "Register".

i.e., if both Beneficiary & Amount match any record in the workshee
"Register" it should prompt the user that it is a duplicate entry & as
if the user wants to continue. Otherwise it should post to th
register.

Any help is greatly appreciated! Thanks in advance

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Excel VBA - Check for Duplicate Records

If I were using a worksheet formula, I could use something like:

=sumproduct(--(register!c1:c9999=beneficiary),--(register!g1:g9999=amount))

If that returns more than 0, then there was a match.

In VBA, I could use that same formula:

Option Explicit
Sub testme()
Dim PVWks As Worksheet
Dim RegWks As Worksheet
Dim LastRow As Long
Dim BeneRng As Range
Dim AmtRng As Range
Dim resp As Long
Dim DuplicateFound As Boolean

Set PVWks = Worksheets("PV")
Set RegWks = Worksheets("reg")

With RegWks
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
Set BeneRng = .Range("c1:c" & LastRow)
Set AmtRng = .Range("G1:g" & LastRow)
End With

resp = vbYes
If Application.Evaluate("sumproduct(--(" _
& BeneRng.Address(external:=True) & "=beneficiary)," _
& "--(" & AmtRng.Address(external:=True) & "=amount))") Then
resp = MsgBox(Prompt:="Duplicate found, Continue?", _
Buttons:=vbYesNo)
End If

If resp = vbYes Then
With RegWks
.Cells(LastRow + 1, "C").Value = PVWks.Range("beneficiary").Value
.Cells(LastRow + 1, "G").Value = PVWks.Range("amount").Value
End With
Else
MsgBox "ok!"
End If

End Sub

I used column C to determine the last used row in the Reg worksheet.



"josnah <" wrote:

HI,

I have two worksheets "PV" & "Register".
PV form is to be completed & will be posted to Register when User
executes the macro "PostToRegister".

I would like to check if the record being posted is a duplicate entry.

There are two cells named "Beneficiary" & "Amount" in the worksheet
"PV" which I want to check against Cols "C" & "G" respectively in
worksheet "Register".

i.e., if both Beneficiary & Amount match any record in the worksheet
"Register" it should prompt the user that it is a duplicate entry & ask
if the user wants to continue. Otherwise it should post to the
register.

Any help is greatly appreciated! Thanks in advance!

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA - Check for Duplicate Records

I just tried it. It worked perfectly!!!
Thank you so much Dave...
I didn't think I could use a Excel formula as well

--
Message posted from http://www.ExcelForum.com

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
Delete records when certain records have duplicate column data JVroom New Users to Excel 1 January 26th 09 06:23 PM
how can i get rid of duplicate records in excel? Amber Excel Worksheet Functions 5 November 10th 08 08:16 PM
How do I locate duplicate records in Excel? Amie G Excel Discussion (Misc queries) 14 November 12th 05 04:59 PM
removing duplicate records in excel, how to do it? Don Excel Discussion (Misc queries) 3 July 27th 05 01:45 AM
Duplicate records in Excel Sheidsa Excel Discussion (Misc queries) 1 November 30th 04 12:23 AM


All times are GMT +1. The time now is 01:28 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"