Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Blank item in listbox, how to remove

Hi,
I am using the following code to populate a listbox from a range.

This works great, unless there is only one item in the range. When
there is only one item, that item shows in the listbox, but along with
a Blank item.
Any time there is more than one item in the range to populate, there
is no blank items brought into the listbox.

Do you know how i can fix this code to work correctly when only one
item is in the range.
Or, do you know of a better way to initialize the form lisbox using
the range, which starts at F8?


Private Sub UserForm_Initialize()
AddStuff Range(Sheets("ToReview Pivot").[F8], Sheets("ToReview
Pivot").[F8].End(xlDown))

End Sub

Sub AddStuff(Data As Range)
Dim d, cel As Range
Set d = CreateObject("Scripting.Dictionary")
For Each cel In Data
On Error Resume Next
d.Add cel.Text, cel.Text
Next
'ComboBox1.List() = d.items
ListBox1.List() = d.items

Me.ListBox1.MultiSelect = fmMultiSelectMulti
Me.ListBox2.MultiSelect = fmMultiSelectMulti


End Sub



Many Thanks,
Steve
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Blank item in listbox, how to remove

See inserted code below:
Hi,
I am using the following code to populate a listbox from a range.

This works great, unless there is only one item in the range. When
there is only one item, that item shows in the listbox, but along with
a Blank item.
Any time there is more than one item in the range to populate, there
is no blank items brought into the listbox.

Do you know how i can fix this code to work correctly when only one
item is in the range.
Or, do you know of a better way to initialize the form lisbox using
the range, which starts at F8?


Private Sub UserForm_Initialize()
AddStuff Range(Sheets("ToReview Pivot").[F8], Sheets("ToReview
Pivot").[F8].End(xlDown))

End Sub

Sub AddStuff(Data As Range)
Dim d, cel As Range
Set d = CreateObject("Scripting.Dictionary")
For Each cel In Data
On Error Resume Next


If cel < "" Then d.Add cel.Text, cel.Text

Next
'ComboBox1.List() = d.items
ListBox1.List() = d.items

Me.ListBox1.MultiSelect = fmMultiSelectMulti
Me.ListBox2.MultiSelect = fmMultiSelectMulti


End Sub



Many Thanks,
Steve


--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Blank item in listbox, how to remove

On Jan 28, 12:01*pm, GS wrote:
See inserted code below:





Hi,
I am using the following code to populate a listbox from a range.


This works great, unless there is only one item in the range. *When
there is only one item, that item shows in the listbox, but along with
a Blank item.
Any time there is more than one item in the range to populate, there
is no blank items brought into the listbox.


Do you know how i can fix this code to work correctly when only one
item is in the range.
Or, do you know of a better way to initialize the form lisbox using
the range, which starts at F8?


Private Sub UserForm_Initialize()
* * AddStuff Range(Sheets("ToReview Pivot").[F8], Sheets("ToReview
Pivot").[F8].End(xlDown))


End Sub


Sub AddStuff(Data As Range)
* * Dim d, cel As Range
* * Set d = CreateObject("Scripting.Dictionary")
* * For Each cel In Data
* * * On Error Resume Next


* * * * If cel < "" Then d.Add cel.Text, cel.Text

* * Next
* * 'ComboBox1.List() = d.items
* * ListBox1.List() = d.items


* * Me.ListBox1.MultiSelect = fmMultiSelectMulti
* * Me.ListBox2.MultiSelect = fmMultiSelectMulti


End Sub


Many Thanks,
Steve


--
Garry

Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc- Hide quoted text -

- Show quoted text -


Works Great!! Thanks Much!!
-Steve
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Blank item in listbox, how to remove

SS has brought this to us :
On Jan 28, 12:01*pm, GS wrote:
See inserted code below:





Hi,
I am using the following code to populate a listbox from a range.
This works great, unless there is only one item in the range. *When
there is only one item, that item shows in the listbox, but along with
a Blank item.
Any time there is more than one item in the range to populate, there
is no blank items brought into the listbox.
Do you know how i can fix this code to work correctly when only one
item is in the range.
Or, do you know of a better way to initialize the form lisbox using
the range, which starts at F8?


Private Sub UserForm_Initialize()
* * AddStuff Range(Sheets("ToReview Pivot").[F8], Sheets("ToReview
Pivot").[F8].End(xlDown))


End Sub


Sub AddStuff(Data As Range)
* * Dim d, cel As Range
* * Set d = CreateObject("Scripting.Dictionary")
* * For Each cel In Data
* * * On Error Resume Next


* * * * If cel < "" Then d.Add cel.Text, cel.Text

* * Next
* * 'ComboBox1.List() = d.items
* * ListBox1.List() = d.items


* * Me.ListBox1.MultiSelect = fmMultiSelectMulti
* * Me.ListBox2.MultiSelect = fmMultiSelectMulti
End Sub


Many Thanks,
Steve


--
Garry

Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc- Hide quoted text -

- Show quoted text -


Works Great!! Thanks Much!!
-Steve


You're welcome! ..glad to help!

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


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
listbox remove item according to the value [email protected] Excel Programming 1 December 31st 07 09:35 AM
remove items from listbox together with add item [email protected] Excel Programming 7 September 23rd 07 01:18 PM
Remove Item from Listbox by Item Name Randy[_2_] Excel Programming 3 September 19th 07 02:36 PM
remove item fr listbox (correction) Baha Excel Programming 2 November 9th 06 01:11 AM
listbox remove Item Simon Shaw Excel Programming 3 July 3rd 05 10:14 PM


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