REpeating Values

G

GBH99

Hello,

I have some code that generates Random draw winners, but if a name is
repeated in the list I want to have a pop-up identifing this and ask me if I
want the name changed or kept the same, this is just in case there is only 1
entry with 3 prizes.

I have placed the code below (I know it is messy but this is the only way I
know how to write code)

Please help

Application.Goto Reference:="Random_Number_Generator"
ActiveCell.FormulaR1C1 = "=ROUND((RAND()*(1-" & ValueMAM & ")+" &
ValueMAM & "),0)"
Application.Goto Reference:="MAM_Winner_1"
ActiveCell.FormulaR1C1 =
"=vlookup(Random_Number_Generator,MAMDraw!A:B,2,0)"
SendKeys "{f2}" & "{Enter}", True
Application.Goto Reference:="MAM_Winner_1"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Application.Goto Reference:="MAM_Winner_2"
ActiveCell.FormulaR1C1 =
"=vlookup(Random_Number_Generator,MAMDraw!A:B,2,0)"
SendKeys "{f2}" & "{Enter}", True
Application.Goto Reference:="MAM_Winner_2"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Application.Goto Reference:="MAM_Winner_3"
ActiveCell.FormulaR1C1 =
"=vlookup(Random_Number_Generator,MAMDraw!A:B,2,0)"
SendKeys "{f2}" & "{Enter}", True
Application.Goto Reference:="MAM_Winner_3"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
 
T

Tom Ogilvy

the basic approach would be:

After you make the entry, then check if it is a duplicate:

if Application.Countif(Range("A1:A50","John")) > 2 then


In corporate something like that in your code.
 
G

GBH99

Hi Tom,

I have tried this and when I added the MSG box in I add a select case
option. Should I be using something else? I have tried
if Application.Countif(Range("A1:A50","John")) > 2 then
MSGBOX DUPERR("Duplicate, Replace?",VBYesNo,"Replace")
Select Case DUPERR
Case 6
ActiveCell.clearcontents
'then I have put the code to create the cell entry again.
Case 7
MSGBOX "Continuing"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top