PDA

View Full Version : Solved: Macro to warning user of duplicate entry



Pete
06-24-2008, 02:50 AM
Hi Experts

Need to add macro to the grey macro button in the main worksheet "sheet 1 row 4 column B.

If the user click this macro button it alows the user to enter a new customer name which then is populated and entered into column B worksheet "Deal Selection" all new entries are add to the bottom i.e. row 13 onwards

I want to the new macro to look in column b worksheet "Sheet 1" and if the user try to enter the same name that alreay exist in column b worksheet "Sheet 1" then >

msg "This Client Name is already exists in the current list - cannot add duplicate name" and exit the step..

Bob Phillips
06-24-2008, 02:58 AM
Sub AddCustomer()
Dim mpName As String
Dim mpPOs As Long

mpName = InputBox("What name?")
If mpName <> "" And mpName <> "fALSE" Then

If Application.CountIf(Columns(2), mpName) > 0 Then

MsgBox "Name already used"
Else

Range("B8").End(xlDown).Offset(1, 0).Value = mpName
End If
End If
End Sub

Simon Lloyd
06-24-2008, 03:02 AM
I've not looked at your workbook but in VBA you can use the worksheet function Vlookup like this

If Application.WorksheetFunction.VLookup(userform1.textbox1.Value, Sheets("Sheet1").Range _
("A2:A" & Range("A" & Rows.Count).End(xlUp).Row), 1, False) = userform1.textbox1.Value Then
assuming you are using a UserForm

Pete
06-24-2008, 04:55 AM
Thanks for the feed back works treat

Simon Lloyd
06-24-2008, 05:38 AM
Thanks for the feed back works treatLol I guess he means you Bob!