Command button caption to show what is selected in the listbox.

danbates

Active Member
Joined
Oct 8, 2017
Messages
377
Office Version
  1. 2016
Platform
  1. Windows
Hi,

Please can someone help me?

I would like my commandbutton1 caption to show what is selected in my listbox1.

Any help would be appreciated.

Thanks

Dan
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi,

Your description is very vague ...

There are several questions one would like to ask ...

Can the following be of any help :

Code:
CommandButton1.Caption = ListBox1.Selected(0)
 
Upvote 0
Assuming that your listbox allows only a single selection, try...

Code:
    With Me.ListBox1
        Me.CommandButton1.Caption = .List(.ListIndex)
    End With

Note, you should check to make sure that a selection from the listbox has been made before trying to set the caption for the commandbutton. When no selection is made, ListIndex is equal to -1, so you can test as follows...

Code:
If Me.ListBox1.ListIndex <> -1 Then

Hope this helps!
 
Upvote 0
Hi,

James006 - Sorry I was vague in my description. Your code shows 'false' on my command button when I make a selection from my listbox.

Domenic - Your code works just how I wanted, thanks.

Thank you both for taking time to help me out.

Regards

Dan
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,205
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top