Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default Remove Duplicate Values

I am loading a Combobox with the below cade, but i want to REMOVE any Values from the LIst IF they
are a Duplicate.
How can i add this in to the below code ?

Private Sub ComboBox5_DropButtonClick()
Application.ScreenUpdating = False
If ComboBox5.ListCount 0 Then Exit Sub
Dim LastCell As Long
Dim myrow As Long
On Error Resume Next
LastCell = Worksheets("Contact List").Cells(Rows.Count, "B").End(xlUp).Row

With ActiveWorkbook.Worksheets("Contact List")
..Select
For myrow = 2 To LastCell

If .Cells(myrow, 2) < "" Then
If Cells(myrow, 2).Value < "" Then
ComboBox5.AddItem Cells(myrow, 2)
End If
End If
Next
End With
End Sub



Corey....


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Remove Duplicate Values

Private Sub ComboBox5_DropButtonClick()
Application.ScreenUpdating = False
Dim nodupes as Collection
If ComboBox5.ListCount 0 Then Exit Sub
Dim LastCell As Long
Dim myrow As Long
On Error Resume Next
LastCell = Worksheets("Contact List").Cells(Rows.Count, "B").End(xlUp).Row

With ActiveWorkbook.Worksheets("Contact List")
..Select
set nodupes = New Collection
For myrow = 2 To LastCell

If .Cells(myrow, 2).Value < "" Then
On error resume Next
nodupes cells(myrow,2).Value, cStr(cells(myrow,2).Value)
if err.Number = 0 then
ComboBox5.AddItem Cells(myrow, 2)
end if
On Error goto 0
End If
Next
End With
End Sub

--
Regards,
Tom Ogilvy



"Corey" wrote in message
...
I am loading a Combobox with the below cade, but i want to REMOVE any
Values from the LIst IF they
are a Duplicate.
How can i add this in to the below code ?

Private Sub ComboBox5_DropButtonClick()
Application.ScreenUpdating = False
If ComboBox5.ListCount 0 Then Exit Sub
Dim LastCell As Long
Dim myrow As Long
On Error Resume Next
LastCell = Worksheets("Contact List").Cells(Rows.Count, "B").End(xlUp).Row

With ActiveWorkbook.Worksheets("Contact List")
.Select
For myrow = 2 To LastCell

If .Cells(myrow, 2) < "" Then
If Cells(myrow, 2).Value < "" Then
ComboBox5.AddItem Cells(myrow, 2)
End If
End If
Next
End With
End Sub



Corey....




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default Remove Duplicate Values

Tom i get an error at this line:
nodupes cells(myrow,2).Value, cStr(cells(myrow,2).Value)


A 'Wrong No of arguements' Comile error??
"Tom Ogilvy" wrote in message ...
Private Sub ComboBox5_DropButtonClick()
Application.ScreenUpdating = False
Dim nodupes as Collection
If ComboBox5.ListCount 0 Then Exit Sub
Dim LastCell As Long
Dim myrow As Long
On Error Resume Next
LastCell = Worksheets("Contact List").Cells(Rows.Count, "B").End(xlUp).Row

With ActiveWorkbook.Worksheets("Contact List")
..Select
set nodupes = New Collection
For myrow = 2 To LastCell

If .Cells(myrow, 2).Value < "" Then
On error resume Next
nodupes cells(myrow,2).Value, cStr(cells(myrow,2).Value)
if err.Number = 0 then
ComboBox5.AddItem Cells(myrow, 2)
end if
On Error goto 0
End If
Next
End With
End Sub

--
Regards,
Tom Ogilvy



"Corey" wrote in message
...
I am loading a Combobox with the below cade, but i want to REMOVE any
Values from the LIst IF they
are a Duplicate.
How can i add this in to the below code ?

Private Sub ComboBox5_DropButtonClick()
Application.ScreenUpdating = False
If ComboBox5.ListCount 0 Then Exit Sub
Dim LastCell As Long
Dim myrow As Long
On Error Resume Next
LastCell = Worksheets("Contact List").Cells(Rows.Count, "B").End(xlUp).Row

With ActiveWorkbook.Worksheets("Contact List")
.Select
For myrow = 2 To LastCell

If .Cells(myrow, 2) < "" Then
If Cells(myrow, 2).Value < "" Then
ComboBox5.AddItem Cells(myrow, 2)
End If
End If
Next
End With
End Sub



Corey....





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Remove Duplicate Values

Replace the lines after your On Error stmt with:

Set ws = Worksheets("Contact List")
LastCell = ws.Cells(Rows.Count, "B").End(xlUp).Row
Set rng = ws.Range("B2:B" & LastCell)
rng.AdvancedFilter Action:=xlFilterInPlace, Unique:=True
Set rng = rng.SpecialCells(xlCellTypeVisible)
With rng
For Each c In rng
ComboBox5.AddItem c
Next
End With
ws.ShowAllData

Hth,
Merjet



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default Remove Duplicate Values

Merjet,
Do you mean:

Private Sub ComboBox5_DropButtonClick()
Application.ScreenUpdating = False
If ComboBox5.ListCount 0 Then Exit Sub
Dim LastCell As Long
Dim myrow As Long
On Error Resume Next
Set ws = Worksheets("Contact List")
LastCell = ws.Cells(Rows.Count, "B").End(xlUp).Row
Set rng = ws.Range("B2:B" & LastCell)
rng.AdvancedFilter Action:=xlFilterInPlace, Unique:=True
Set rng = rng.SpecialCells(xlCellTypeVisible)
With rng
For Each c In rng
ComboBox5.AddItem c
Next
End With
ws.ShowAllData
Application.ScreenUpdating = True
End Sub

Like the baove.
I get NO error's but i still get DUPLICATE Values??

Corey....
"merjet" wrote in message
oups.com...
Replace the lines after your On Error stmt with:

Set ws = Worksheets("Contact List")
LastCell = ws.Cells(Rows.Count, "B").End(xlUp).Row
Set rng = ws.Range("B2:B" & LastCell)
rng.AdvancedFilter Action:=xlFilterInPlace, Unique:=True
Set rng = rng.SpecialCells(xlCellTypeVisible)
With rng
For Each c In rng
ComboBox5.AddItem c
Next
End With
ws.ShowAllData

Hth,
Merjet






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default Remove Duplicate Values

Are you sure there is no item in ComboBox5 when you run this code first
time?
if not, i think you need to remove all items before this.

keizi

"Corey" wrote in message
...
Merjet,
Do you mean:

Private Sub ComboBox5_DropButtonClick()
Application.ScreenUpdating = False
If ComboBox5.ListCount 0 Then Exit Sub
Dim LastCell As Long
Dim myrow As Long
On Error Resume Next
Set ws = Worksheets("Contact List")
LastCell = ws.Cells(Rows.Count, "B").End(xlUp).Row
Set rng = ws.Range("B2:B" & LastCell)
rng.AdvancedFilter Action:=xlFilterInPlace, Unique:=True
Set rng = rng.SpecialCells(xlCellTypeVisible)
With rng
For Each c In rng
ComboBox5.AddItem c
Next
End With
ws.ShowAllData
Application.ScreenUpdating = True
End Sub

Like the baove.
I get NO error's but i still get DUPLICATE Values??

Corey....
"merjet" wrote in message
oups.com...
Replace the lines after your On Error stmt with:

Set ws = Worksheets("Contact List")
LastCell = ws.Cells(Rows.Count, "B").End(xlUp).Row
Set rng = ws.Range("B2:B" & LastCell)
rng.AdvancedFilter Action:=xlFilterInPlace, Unique:=True
Set rng = rng.SpecialCells(xlCellTypeVisible)
With rng
For Each c In rng
ComboBox5.AddItem c
Next
End With
ws.ShowAllData

Hth,
Merjet





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Remove Duplicate Values

My typo:

nodupes.Add cells(myrow,2).Value, cStr(cells(myrow,2).Value)


--
Regards,
Tom Ogilvy

"Corey" wrote in message
...
Tom i get an error at this line:
nodupes cells(myrow,2).Value, cStr(cells(myrow,2).Value)


A 'Wrong No of arguements' Comile error??
"Tom Ogilvy" wrote in message
...
Private Sub ComboBox5_DropButtonClick()
Application.ScreenUpdating = False
Dim nodupes as Collection
If ComboBox5.ListCount 0 Then Exit Sub
Dim LastCell As Long
Dim myrow As Long
On Error Resume Next
LastCell = Worksheets("Contact List").Cells(Rows.Count, "B").End(xlUp).Row

With ActiveWorkbook.Worksheets("Contact List")
.Select
set nodupes = New Collection
For myrow = 2 To LastCell

If .Cells(myrow, 2).Value < "" Then
On error resume Next
nodupes cells(myrow,2).Value, cStr(cells(myrow,2).Value)
if err.Number = 0 then
ComboBox5.AddItem Cells(myrow, 2)
end if
On Error goto 0
End If
Next
End With
End Sub

--
Regards,
Tom Ogilvy



"Corey" wrote in message
...
I am loading a Combobox with the below cade, but i want to REMOVE any
Values from the LIst IF they
are a Duplicate.
How can i add this in to the below code ?

Private Sub ComboBox5_DropButtonClick()
Application.ScreenUpdating = False
If ComboBox5.ListCount 0 Then Exit Sub
Dim LastCell As Long
Dim myrow As Long
On Error Resume Next
LastCell = Worksheets("Contact List").Cells(Rows.Count,
"B").End(xlUp).Row

With ActiveWorkbook.Worksheets("Contact List")
.Select
For myrow = 2 To LastCell

If .Cells(myrow, 2) < "" Then
If Cells(myrow, 2).Value < "" Then
ComboBox5.AddItem Cells(myrow, 2)
End If
End If
Next
End With
End Sub



Corey....







  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Remove Duplicate Values

Corey,
You had your code in the ComboBox5_DropButtonClick event. It should
probably be elsewhere, e.g. Userform_Initialize, or as kounoike
suggested, clear ComboBox5 before populating it (in case the user
clicks the DropButton more than once).

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
Remove Duplicate with 'Caveat' msnyc07 Excel Worksheet Functions 2 December 29th 09 04:01 AM
remove all duplicate records dberger16 Excel Discussion (Misc queries) 1 September 17th 09 06:36 PM
DUPLICATE SPREADSHEET ,CANNOT REMOVE DOUG Excel Discussion (Misc queries) 2 August 11th 08 09:06 PM
remove duplicate records Valori Excel Discussion (Misc queries) 1 April 23rd 07 08:04 PM
is there a formula that remove duplicate values from a range Martin R Excel Worksheet Functions 3 June 20th 06 01:10 PM


All times are GMT +1. The time now is 09:36 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"