#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 172
Default Listbox value

I want to create a command button that will default back my listbox to "All"
when a user clicks the command button. How would I write the VBA code for
this button to have it select "All" from my listbox. I just want to create an
easy way for users to select that particular value.
  #2   Report Post  
Posted to microsoft.public.excel.misc
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Listbox value

That depends - is your listbox in a UserForm, or embedded in a worksheet? If
on a worksheet, is it created by the control toolbox or the forms toolbar?

If the list and commandbutton are in a UserForm or the listbox and
commandbutton are created using the control toolbox, just set the value of
the Listbox:

Private Sub CommandButton1_Click()
Me.ListBox1.Value = "all"
End Sub

Listbox name and the CommandButton1_Click depend on the actual names of the
listbox and command button you create.

If your listbox and command button are created w/the forms toolbar, assign
your button to a macro similar to:

Sub test()
ActiveSheet.Shapes("List Box 1").ControlFormat.ListIndex = 5
End Sub

where "all" is the 5th item in the list. Of course, change the name of the
list box to whatever yours is/will be called. If it's the only one on your
sheet, it is probably List Box 1.



"Secret Squirrel" wrote:

I want to create a command button that will default back my listbox to "All"
when a user clicks the command button. How would I write the VBA code for
this button to have it select "All" from my listbox. I just want to create an
easy way for users to select that particular value.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 172
Default Listbox value

My listbox is embedded on my worksheet and was created using the control
toolbox. Your instructions worked great.

Thanks again for your help tonight!

"JMB" wrote:

That depends - is your listbox in a UserForm, or embedded in a worksheet? If
on a worksheet, is it created by the control toolbox or the forms toolbar?

If the list and commandbutton are in a UserForm or the listbox and
commandbutton are created using the control toolbox, just set the value of
the Listbox:

Private Sub CommandButton1_Click()
Me.ListBox1.Value = "all"
End Sub

Listbox name and the CommandButton1_Click depend on the actual names of the
listbox and command button you create.

If your listbox and command button are created w/the forms toolbar, assign
your button to a macro similar to:

Sub test()
ActiveSheet.Shapes("List Box 1").ControlFormat.ListIndex = 5
End Sub

where "all" is the 5th item in the list. Of course, change the name of the
list box to whatever yours is/will be called. If it's the only one on your
sheet, it is probably List Box 1.



"Secret Squirrel" wrote:

I want to create a command button that will default back my listbox to "All"
when a user clicks the command button. How would I write the VBA code for
this button to have it select "All" from my listbox. I just want to create an
easy way for users to select that particular value.

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 2 takes the value of Listbox 1 Illya Teideman Excel Discussion (Misc queries) 3 April 10th 07 03:20 PM
listbox B conditional of input in Listbox A Kim K Excel Discussion (Misc queries) 1 October 31st 06 08:27 PM
Listbox B if LIstbox A equals Kim K Excel Discussion (Misc queries) 2 October 31st 06 07:03 PM
Need help with Listbox Lizzie_S Excel Discussion (Misc queries) 3 July 22nd 05 03:42 AM
Listbox Greg B Excel Discussion (Misc queries) 1 March 9th 05 02:18 PM


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