Warning Msg with VBA

Ekstamm

New Member
Joined
Jul 21, 2011
Messages
19
Hi.
As Im already using validation list I cannot use validation to determin and warn for duplicates. So I need to use VBA right? And this I have no clue how to do.

Anyone help me with this?

Its D8:D19 I need to check for duplicates.
Using Excel 2011 for mac
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try this: right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D8:D19")) Is Nothing Then
    If WorksheetFunction.CountIf(Range("D8:D19"), Target.Value) > 1 Then
        MsgBox "Duplicate in " & Target.Address(False, False), vbExclamation
    End If
End If
End Sub
 
Upvote 0
You can use conditional formating if you want to find only duplicates..
In Cond'l Formatting..
FormulaIs...
=CountIf(D$8:D$19,D8)>1
 
Upvote 0
Thx, Seams to work fine! Just need some tweaking.
I need to be able to duplicate "x" but no numbers.
 
Upvote 0
Yes..only to show that there are dupliactes...
You can use VoG's code in VBA to give you the mesage.
 
Upvote 0
VoGs code works just fine for me. I just need it tweaked so that I can duplicate "x". Trying to figure out how to do it.
 
Upvote 0
Try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D8:D19")) Is Nothing Then
    If Target.Value = "x" Then Exit Sub
    If WorksheetFunction.CountIf(Range("D8:D19"), Target.Value) > 1 Then
        MsgBox "Duplicate in " & Target.Address(False, False), vbExclamation
    End If
End If
End Sub
 
Upvote 0
VoGs code works just fine for me. I just need it tweaked so that I can duplicate "x". Trying to figure out how to do it.
I'm assuming "x" is meant to stand in for any non-numeric text. Give this modification to VoG's code a try...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("D8:D19")) Is Nothing Then
        If WorksheetFunction.IsNumber(Target) Then
            If WorksheetFunction.CountIf(Range("D8:D19"), Target.Value) > 1 Then
                MsgBox "Duplicate in " & Target.Address(False, False), vbExclamation
                Target.Select
            End If
        End If
    End If
End Sub
Note that I added a Target.Select statement so that the offending duplicated number would be reselected.
 
Upvote 0
I'm assuming "x" is meant to stand in for any non-numeric text. Give this modification to VoG's code a try...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("D8:D19")) Is Nothing Then
        If WorksheetFunction.IsNumber(Target) Then
            If WorksheetFunction.CountIf(Range("D8:D19"), Target.Value) > 1 Then
                MsgBox "Duplicate in " & Target.Address(False, False), vbExclamation
                Target.Select
            End If
        End If
    End If
End Sub
Note that I added a Target.Select statement so that the offending duplicated number would be reselected.

That modification made the trick!
THX so much! I have been struggling for a couple of days with that.
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,183
Members
452,893
Latest member
denay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top