Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 312
Default Check for Duplicates (RP)

Hi. The code below is compliments of Bob Phillips. It scans the contents
of column D, and finds duplicates. If the code finds them, a message box
displaying where the dulicates are found is displayed. This code works
great if there are duplicates found. If there are no duplicates, I get an
Invalid procedure call or argument error, with the line sCells =
Left(sCells, Len(sCells) - 1) highlighted by the debugger. Any ideas how
to fix? Thank you!!

Sub Dups()
Dim iLastRow As Long
Dim i As Long
Dim sCells As String
Dim rng As Range

iLastRow = Cells(1499, "B").End(xlUp).Row 'Cells(Rows.Count, "B")
Set rng = Range("D1:D" & iLastRow)
For i = 1 To iLastRow
If Application.CountIf(rng, Cells(i, "D")) 1 Then
sCells = sCells & Cells(i, "D").Address(False, False) & ","
End If
Next i
sCells = Left(sCells, Len(sCells) - 1)
If Not IsEmpty(sCells) Then
MsgBox "Duplicates found in " & vbCrLf & sCells
Else
MainUpdate
End If
End Sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Check for Duplicates (RP)

sCells will never be empty since it is initialized as a null string. But
you can do

Sub Dups()
Dim iLastRow As Long
Dim i As Long
Dim sCells As String
Dim rng As Range

iLastRow = Cells(1499, "B").End(xlUp).Row 'Cells(Rows.Count, "B")
Set rng = Range("D1:D" & iLastRow)
For i = 1 To iLastRow
If Application.CountIf(rng, Cells(i, "D")) 1 Then
sCells = sCells & Cells(i, "D").Address(False, False) & ","
End If
Next i
If sCells < "" Then
sCells = Left(sCells, Len(sCells) - 1)
MsgBox "Duplicates found in " & vbCrLf & sCells
Else
MainUpdate
End If
End Sub

--
Regards,
Tom Ogilvy

"Steph" wrote in message
...
Hi. The code below is compliments of Bob Phillips. It scans the contents
of column D, and finds duplicates. If the code finds them, a message box
displaying where the dulicates are found is displayed. This code works
great if there are duplicates found. If there are no duplicates, I get an
Invalid procedure call or argument error, with the line sCells =
Left(sCells, Len(sCells) - 1) highlighted by the debugger. Any ideas how
to fix? Thank you!!

Sub Dups()
Dim iLastRow As Long
Dim i As Long
Dim sCells As String
Dim rng As Range

iLastRow = Cells(1499, "B").End(xlUp).Row 'Cells(Rows.Count, "B")
Set rng = Range("D1:D" & iLastRow)
For i = 1 To iLastRow
If Application.CountIf(rng, Cells(i, "D")) 1 Then
sCells = sCells & Cells(i, "D").Address(False, False) & ","
End If
Next i
sCells = Left(sCells, Len(sCells) - 1)
If Not IsEmpty(sCells) Then
MsgBox "Duplicates found in " & vbCrLf & sCells
Else
MainUpdate
End If
End Sub





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 312
Default Check for Duplicates (RP)

Thanks Tom!

"Tom Ogilvy" wrote in message
...
sCells will never be empty since it is initialized as a null string. But
you can do

Sub Dups()
Dim iLastRow As Long
Dim i As Long
Dim sCells As String
Dim rng As Range

iLastRow = Cells(1499, "B").End(xlUp).Row 'Cells(Rows.Count, "B")
Set rng = Range("D1:D" & iLastRow)
For i = 1 To iLastRow
If Application.CountIf(rng, Cells(i, "D")) 1 Then
sCells = sCells & Cells(i, "D").Address(False, False) & ","
End If
Next i
If sCells < "" Then
sCells = Left(sCells, Len(sCells) - 1)
MsgBox "Duplicates found in " & vbCrLf & sCells
Else
MainUpdate
End If
End Sub

--
Regards,
Tom Ogilvy

"Steph" wrote in message
...
Hi. The code below is compliments of Bob Phillips. It scans the

contents
of column D, and finds duplicates. If the code finds them, a message

box
displaying where the dulicates are found is displayed. This code works
great if there are duplicates found. If there are no duplicates, I get

an
Invalid procedure call or argument error, with the line sCells =
Left(sCells, Len(sCells) - 1) highlighted by the debugger. Any ideas

how
to fix? Thank you!!

Sub Dups()
Dim iLastRow As Long
Dim i As Long
Dim sCells As String
Dim rng As Range

iLastRow = Cells(1499, "B").End(xlUp).Row 'Cells(Rows.Count, "B")
Set rng = Range("D1:D" & iLastRow)
For i = 1 To iLastRow
If Application.CountIf(rng, Cells(i, "D")) 1 Then
sCells = sCells & Cells(i, "D").Address(False, False) & ","
End If
Next i
sCells = Left(sCells, Len(sCells) - 1)
If Not IsEmpty(sCells) Then
MsgBox "Duplicates found in " & vbCrLf & sCells
Else
MainUpdate
End If
End Sub







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
Check for duplicates? Vass[_2_] Excel Worksheet Functions 5 October 24th 07 11:12 PM
check for duplicates Todd Excel Worksheet Functions 0 November 7th 06 05:59 PM
Check for Duplicates Carter68 Excel Worksheet Functions 3 April 15th 06 12:13 AM
Check for Duplicates nebb Excel Worksheet Functions 2 February 13th 06 02:39 PM
Check for duplicates Pat Excel Worksheet Functions 8 February 17th 05 10:06 PM


All times are GMT +1. The time now is 12:01 PM.

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"