ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   unique text additem combobox (https://www.excelbanter.com/excel-programming/341619-unique-text-additem-combobox.html)

CG Rosén

unique text additem combobox
 
Good Day Group,

When using the below code to "fill" a ComboBox how to ensure that
only unique text will be added. The text that is in Range ("A1:A1000") is of
this type:
001
001
001
002
003
003
004
as a result I would like the combobox listtext to show
001
002
003
004 etc

Brgds

CG Rosén
----------------------------------------------------------------------------------------------
With Worksheets("Sheet").Range("A1:A1000")

Set k = .Find(nr, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns)

If Not k Is Nothing Then
firstAddress = k.Address
Do

r = k.Row

Me.ComboBox1.AddItem Mid(Sheets("Sheet1").Cells(r, 1).Text, 1, 3)

Set k = .FindNext(k)
Loop While Not k Is Nothing And k.Address < firstAddress
End If

End With



Tom Ogilvy

unique text additem combobox
 
See John Walkenbach's site for one method:

http://www.j-walk.com/ss/excel/tips/tip47.htm

--
Regards,
Tom Ogilvy


"CG Rosén" wrote in message
...
Good Day Group,

When using the below code to "fill" a ComboBox how to ensure that
only unique text will be added. The text that is in Range ("A1:A1000") is

of
this type:
001
001
001
002
003
003
004
as a result I would like the combobox listtext to show
001
002
003
004 etc

Brgds

CG Rosén
--------------------------------------------------------------------------

--------------------
With Worksheets("Sheet").Range("A1:A1000")

Set k = .Find(nr, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns)

If Not k Is Nothing Then
firstAddress = k.Address
Do

r = k.Row

Me.ComboBox1.AddItem Mid(Sheets("Sheet1").Cells(r, 1).Text, 1, 3)

Set k = .FindNext(k)
Loop While Not k Is Nothing And k.Address < firstAddress
End If

End With






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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com