Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Checking for duplicates: VBA

Hi

Does anyone know a neat VBA way of checking for duplicates in a column. I
use OFFSET to get to a particular cell but then need to check whether the
one (or more) below it contain identical data (numeric)...

This is a scoring system and I'm trying to check for ties. I OFFSET to 7th
place which shows 7 in the cell but then need to check the next cell down to
see if that is 7 (and maybe the next one too).

Hope that makes sense. Any suggestions gratefully received!

Jim


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Checking for duplicates: VBA

I use the COUNTIF worksheet function - e.g.
CountTies = WorksheetFunction.Countif(YourCell.EntireColumn,Yo urCell.Value)
If this comes out 1, then there are that many "tied" scores for that value.

"Jim" wrote:

Hi

Does anyone know a neat VBA way of checking for duplicates in a column. I
use OFFSET to get to a particular cell but then need to check whether the
one (or more) below it contain identical data (numeric)...

This is a scoring system and I'm trying to check for ties. I OFFSET to 7th
place which shows 7 in the cell but then need to check the next cell down to
see if that is 7 (and maybe the next one too).

Hope that makes sense. Any suggestions gratefully received!

Jim



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Checking for duplicates: VBA


With ActiveCell
If .Offset(7,0).Value = .Offset(8,0).Value Then
Msgbox "same"
End If
End With


With ActiveCell
If .Offset(7,0).Value = .Offset(8,0).Value And _
.Offset(7,0).Value = .Offset(9,0).Value Then
Msgbox "same"
End If
End With


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Jim" wrote in message
...
Hi

Does anyone know a neat VBA way of checking for duplicates in a column. I
use OFFSET to get to a particular cell but then need to check whether the
one (or more) below it contain identical data (numeric)...

This is a scoring system and I'm trying to check for ties. I OFFSET to 7th
place which shows 7 in the cell but then need to check the next cell down

to
see if that is 7 (and maybe the next one too).

Hope that makes sense. Any suggestions gratefully received!

Jim




  #4   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Checking for duplicates: VBA

Jim - Here is a macro I use to run down a column and check for duplicate
numbers. If a set of duplicates are found, the first one is changed to
"AAA" and the second is colored red. A formula is then inserted at the
bottom to count how many "AAA" cells - or how many duplicates - were found.
Righ now, it's hard-coded to count down Col. C and put the formula at the
bottom of Col. D.

HTH
Ed

Sub FindDups()
'
' FindDups Macro
Dim FirstItem As String, SecondItem As String
Dim Offsetcount As Long

' Select column
Range("C1").Select
ScreenUpdating = False

' Run down column and compare TIR numbers
FirstItem = ActiveCell.Value
SecondItem = ActiveCell.Offset(1, 0).Value
Offsetcount = 1

' If the numbers are the same
Do While ActiveCell < ""
If FirstItem = SecondItem Then

' Turns the second one red
ActiveCell.Offset(Offsetcount, 0).Interior.Color = RGB(255, 0, 0)
' Replaces first cell value with AAA
ActiveCell.FormulaR1C1 = "AAA"
Offsetcount = Offsetcount + 1
SecondItem = ActiveCell.Offset(Offsetcount, 0).Value
Else
ActiveCell.Offset(Offsetcount, 0).Select
FirstItem = ActiveCell.Value
SecondItem = ActiveCell.Offset(1, 0).Value
Offsetcount = 1
End If
Loop
ScreenUpdating = True

'Puts formula to count AAA values in D column
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "=COUNTIF(C:C,AAA)"
ActiveCell.Select
ActiveCell.FormulaR1C1 = "=COUNTIF(C[-1],""AAA"")"
ActiveCell.Select

Range("C65536").End(xlUp).Offset(1, 1).Select

End Sub

"Jim" wrote in message
...
Hi

Does anyone know a neat VBA way of checking for duplicates in a column. I
use OFFSET to get to a particular cell but then need to check whether the
one (or more) below it contain identical data (numeric)...

This is a scoring system and I'm trying to check for ties. I OFFSET to 7th
place which shows 7 in the cell but then need to check the next cell down

to
see if that is 7 (and maybe the next one too).

Hope that makes sense. Any suggestions gratefully received!

Jim




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Checking for duplicates: VBA

Many thanks for the quick replies. I think Bob's or Ed's suggestions will
bear fruit. Thanks again.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking for Duplicates within a Workbook RAYCV Excel Worksheet Functions 7 September 23rd 08 12:10 PM
checking for duplicates Ted Metro Excel Worksheet Functions 1 April 3rd 07 05:42 PM
Checking for duplicates - think this is simple [email protected] Excel Discussion (Misc queries) 9 February 27th 06 09:32 PM
Checking entire row for duplicates Tom Ogilvy Excel Programming 0 July 14th 04 06:26 PM
Checking for duplicates? Eric G[_3_] Excel Programming 4 April 8th 04 02:54 AM


All times are GMT +1. The time now is 06:24 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"