Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default filtering out duplicate data values

can someone help me modify this code so that my combobox filters out
duplicate values?

Private Sub UserForm_Initialize()
Dim ListStates As Variant, i As Integer
Dim SourceWB As Workbook

With Me.cboState
.Clear ' remove existing entries from the listbox
' turn screen updating off,
' prevent seeing source workbook being opened
Application.ScreenUpdating = False
' open source workbook as ReadOnly
Set SourceWB = Workbooks.Open("H:\Project Tracking db\FY08 Per
Diem Rates.xls", _
False, True)
ListStates = SourceWB.Worksheets(1).Range("A4:A666").Value
' get values
SourceWB.Close False ' close source workbook without saving
Set SourceWB = Nothing
ListStates =
Application.WorksheetFunction.Transpose(ListStates )
' convert values to a vertical array
For i = 1 To UBound(ListStates)
.AddItem ListStates(i) ' populate the listbox
Next i
.ListIndex = -1 ' no items selected, set to 0 to select the
first item
Application.ScreenUpdating = True
End With
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default filtering out duplicate data values

One method of filtering out the duplicates is to use a collection. Items in
a collection cannot have the same "key", so you can temporarily disable error
handling, add all of the values to the collection (using the value as it's
own "key"), then add your collection of unique values to the listbox. An
example using some dummy data I set up in A1:A8 on my end:

Sub test()
Dim v As Variant
Dim colUnique As Collection
Dim i As Long

Set colUnique = New Collection
v = Application.Transpose(Range("A1:A8").Value)

On Error Resume Next
For i = LBound(v) To UBound(v)
colUnique.Add v(i), CStr(v(i))
Next i
On Error GoTo 0

For i = 1 To colUnique.Count
MsgBox colUnique(i)
'Add values to Listbox
Next i

End Sub

" wrote:

can someone help me modify this code so that my combobox filters out
duplicate values?

Private Sub UserForm_Initialize()
Dim ListStates As Variant, i As Integer
Dim SourceWB As Workbook

With Me.cboState
.Clear ' remove existing entries from the listbox
' turn screen updating off,
' prevent seeing source workbook being opened
Application.ScreenUpdating = False
' open source workbook as ReadOnly
Set SourceWB = Workbooks.Open("H:\Project Tracking db\FY08 Per
Diem Rates.xls", _
False, True)
ListStates = SourceWB.Worksheets(1).Range("A4:A666").Value
' get values
SourceWB.Close False ' close source workbook without saving
Set SourceWB = Nothing
ListStates =
Application.WorksheetFunction.Transpose(ListStates )
' convert values to a vertical array
For i = 1 To UBound(ListStates)
.AddItem ListStates(i) ' populate the listbox
Next i
.ListIndex = -1 ' no items selected, set to 0 to select the
first item
Application.ScreenUpdating = True
End With
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 791
Default filtering out duplicate data values


Tyr this:
Private Sub UserForm_Initialize()

Dim ListStates As Variant, i As Integer

Dim SourceWB As Workbook



With Me.cboState

.Clear ' remove existing entries from the listbox

' turn screen updating off,

' prevent seeing source workbook being opened

Application.ScreenUpdating = False

' open source workbook as ReadOnly

Set SourceWB = Workbooks.Open("H:\Project Tracking db\FY08 Per

Diem Rates.xls", _

False, True)

SourceWB.Worksheets(1).Range("A4:A666").AdvancedFi lter
xlFilterInPlace
ListStates = SourceWB.Worksheets(1).Range("A4:A666").Value

' get values

SourceWB.Close False ' close source workbook without saving

Set SourceWB = Nothing

ListStates =

Application.WorksheetFunction.Transpose(ListStates )

' convert values to a vertical array

For i = 1 To UBound(ListStates)

.AddItem ListStates(i) ' populate the listbox

Next i

.ListIndex = -1 ' no items selected, set to 0 to select the

first item

Application.ScreenUpdating = True

End With


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
Filtering data based on historical values Jim Excel Discussion (Misc queries) 1 June 4th 10 09:31 AM
FILTERING DATA VALUES JURBOP Excel Worksheet Functions 1 September 30th 08 08:34 AM
Filtering Data in ranges and changing duplicate cells to a color looneylmt Setting up and Configuration of Excel 2 March 28th 08 06:51 PM
filtering data to include values only if x and y exist Hans Excel Discussion (Misc queries) 4 November 5th 07 06:51 AM
Filtering Duplicate Data to obtain Unique record EricB Excel Worksheet Functions 8 May 8th 07 07:54 AM


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

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"