Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default Why does this code remove Duplicate Values, by showing only 1, but it does NOT show Unique values for some reason ?

Private Sub UserForm_Activate()
'Load the List of Customer Contacts
Application.ScreenUpdating = False
Dim LastCell As Long
Dim myrow As Long
Dim NoDupes As Collection
On Error Resume Next
LastCell = Worksheets("Contact List").Cells(Rows.Count, "A").End(xlUp).Row
With Sheets("Contact List")
..Select
Set NoDupes = New Collection
For myrow = 1 To LastCell
If .Cells(myrow, 1) < "" Then
NoDupes.Add .Cells(myrow, 1).Value, CStr(.Cells(myrow, 1).Value)
If Err.Number = 0 Then
ListBox1.AddItem Cells(myrow, 1)
End If
End If
Next
End With
Sheets("NavigationPage").Activate
Application.ScreenUpdating = True
End Sub


I have 2 values that are duplicates, there are loaded into the Listbox but ALL other (unique) values
are NOT populating??

Corey....


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Why does this code remove Duplicate Values, by showing only 1, but it does NOT show Unique values for some reason ?

If Err.Number = 0 Then
ListBox1.AddItem Cells(myrow, 1)
Else
' Reset Err.number to zero
On Error Resume Next
End If

Err.Number becomes non-zero when you try to add a dupe to the collection.
You never reset it after that, so nothing ever gets added to the list box.
Any "On Error" statement will reset Err.Number and allow an accurate
evaluation on the next loop iteration.

I have to assume that the 2 entries that do get added to the list box are
simply the first 2 rows that get processed & that the 3rd row is the first
"dupe" encountered.

HTH,



"Corey" wrote in message
...
Private Sub UserForm_Activate()
'Load the List of Customer Contacts
Application.ScreenUpdating = False
Dim LastCell As Long
Dim myrow As Long
Dim NoDupes As Collection
On Error Resume Next
LastCell = Worksheets("Contact List").Cells(Rows.Count, "A").End(xlUp).Row
With Sheets("Contact List")
.Select
Set NoDupes = New Collection
For myrow = 1 To LastCell
If .Cells(myrow, 1) < "" Then
NoDupes.Add .Cells(myrow, 1).Value, CStr(.Cells(myrow, 1).Value)
If Err.Number = 0 Then
ListBox1.AddItem Cells(myrow, 1)
End If
End If
Next
End With
Sheets("NavigationPage").Activate
Application.ScreenUpdating = True
End Sub


I have 2 values that are duplicates, there are loaded into the Listbox but
ALL other (unique) values
are NOT populating??

Corey....




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Why does this code remove Duplicate Values, by showing only 1, but it does NOT show Unique values for some reason ?

When a duplicate is found Err.Number < 0 and it stays that way.
Between the two "End If" stmts, insert "Err.Clear". That will reset
Err.Number = 0 and allow more additions.

Hth,
Merjet

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default Why does this code remove Duplicate Values, by showing only 1, but it does NOT show Unique values for some reason ?

Thank you.
Perfect.
I will add that info to my growing VB vocabulary of knowledge.
"merjet" wrote in message
oups.com...
When a duplicate is found Err.Number < 0 and it stays that way.
Between the two "End If" stmts, insert "Err.Clear". That will reset
Err.Number = 0 and allow more additions.

Hth,
Merjet


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Why does this code remove Duplicate Values, by showing only 1, but it does NOT show Unique values for some reason ?

Corey,

Remember this back on 19 February:

You have to clear the error to check the next value. Adjustments made to
your code. Same reason then.


Private Sub ListBox1_Click()
Application.ScreenUpdating = False
If ComboBox1.ListCount 0 Then ComboBox1.Clear
Dim LastCell As Long
Dim myrow As Long
Dim nodupes As Collection
On Error Resume Next
LastCell = Worksheets("Data").Cells(Rows.Count, "BH").End(xlUp).Row
With ActiveWorkbook.Worksheets("Data")
.Select
Set nodupes = New Collection
For myrow = 1 To LastCell
If .Cells(myrow, 5).Value = ListBox1.Value Then
If .Cells(myrow, 60) < "" Then
nodupes.Add .Cells(myrow, 60).Value, CStr(.Cells(myrow, 60).Value)
If Err.Number = 0 Then
ComboBox1.AddItem .Cells(myrow, 60)
else
err.clear
End If
End If
End If
Next
End With
Application.ScreenUpdating = True
End Sub

Just trying to help you "learn" this fact

--
Regards,
Tom Ogilvy

"Corey" wrote in message
...
Thank you.
Perfect.
I will add that info to my growing VB vocabulary of knowledge.
"merjet" wrote in message
oups.com...
When a duplicate is found Err.Number < 0 and it stays that way.
Between the two "End If" stmts, insert "Err.Clear". That will reset
Err.Number = 0 and allow more additions.

Hth,
Merjet




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
Display only duplicate values and delete UNIQUE Items WYMMIY Excel Discussion (Misc queries) 2 August 25th 08 12:50 PM
HOW DO I REMOVE UNIQUE VALUES IN EXCEL? andy Excel Worksheet Functions 3 November 29th 07 02:56 AM
Remove Duplicate Values Corey Excel Programming 7 February 16th 07 01:07 PM
Return Unique Consecutive Duplicate Values across Single Row Sam via OfficeKB.com Excel Worksheet Functions 22 February 6th 07 11:44 AM
Return Unique Duplicate Numeric Values across Single Row Sam via OfficeKB.com Excel Worksheet Functions 7 January 21st 07 02:51 AM


All times are GMT +1. The time now is 05:30 AM.

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

About Us

"It's about Microsoft Excel"