View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
freddy freddy is offline
external usenet poster
 
Posts: 87
Default How do I make sure I don't repeat a value in my worksheet?

Ardus, please allow me to insert a two-fold question regarding your code
below. I've tested it and it works. I see that it checks for duplicate values
as they are being entered. However, can it be incorporated into existing VB
code to run in a macro, or, can a column of values be checked for duplicate
entries AFTER all values have been entered?

"Ardus Petus" wrote:

Paste the following code into your Worksheet's code:

'----------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'Adjust next constant to your own needs
Const myColumn As String = "B"
Dim rng As Range
Dim Found As Range

Set rng = Columns(myColumn)
If Intersect(Target, rng) Is Nothing Then Exit Sub
Set Found = rng.Find(Target.Value)
If Found.Address < Target.Address Then MsgBox ("Duplicate code")
End Sub
'-----------------------------------

HTH
--
AP

"Abby" a écrit dans le message de
...
I want a warning to appear when I enter a duplicate code.

"Ardus Petus" wrote:

Do you want a warning to appear upon input of a duplicate code?

Or else, do you want to check for duplicates in existing codes?

Cheers,
--
AP

"Abby" a écrit dans le message de
...
I am creating a work sheet for CPT codes, showing what was billed and

what
was allowed by the insurance company. Codes are sorted in numerical
order.
How do I make sure that I don't repeat one?