Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Daryl Butler   on Feb 16 In MS Office Category.

  
Question Answered By: Xander Thompson   on Feb 16

If you're trying to write a function, then you must be expecting
to use the function  either in a Subroutine, (or another Function) or
in a cell...

either way, Excel already has a function that does what you're
asking..(Countif)
Let's say you have:
A1 = 9
A2 = 13
A3 = 30
A4 = 89
A5 = 16
A6 = 58
A7 = 9
A8 = 63
A9 = 58
A10 = 12

in B1, you can put: =IF(COUNTIF($A$1:$A$10,A1)>1,A1,"")
The countif will look in the range  A1-A10 for a match to A1,
if more than one match is found, it will display the value of A1.
you can then copy this formula...

if you're trying to use it in a function or Subroutine, you can use
something like:

Sub Check_Dup()
Dim I
For I = 1 To 10
If (Application.WorksheetFunction.CountIf(Range("A1:A10"),
Cells(I, 1)) > 1) Then
MsgBox Cells(I, 1) & " is Duplicated"
End If
Next I
End Sub

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Scanning through a Range Or get search suggestion and latest updates.


Tagged: