selected toggle buttons to fill in worksheet

donny1shot

New Member
Joined
Mar 8, 2018
Messages
18
Hi all,
I am trying to use toggle buttons to fill in part of a work sheet and I am trying to get if either one or more are selected the those captions will auto fill a particular cell. However my current code only fills in the final if please help.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I asked this question which you never answered.

Do you want "D5" to look like this:
Apollo
George
Bob
Jane
Jack

Or like
Apollo George Bob Jane Jack
And if like this do we need spaces between each word.


 
Upvote 0
Assuming You now have a listbox on your Userform try this''
And assuming your Listbox is name ListBox1

And since you never answered how you want the values entered this script does it two different ways

It will enter values in "D4" and "G4"

Modify the script to your needs.


One enters the values horizontally the other vertically

You can choose more then one value from the listbox

And my button that runs this script is named CommandButton1

Code:
Private Sub CommandButton1_Click()
Dim i As Long
   
    For i = 0 To ListBox1.ListCount - 1
        If ListBox1.Selected(i) Then
            Range("D4").Value = Range("D4").Value & ListBox1.List(i) & vbNewLine
            Range("G4").Value = Range("G4").Value & ListBox1.List(i) & " "
        End If
    Next
End Sub
Private Sub UserForm_Initialize()
ListBox1.AddItem "Alpha"
ListBox1.AddItem "Bravo"
ListBox1.AddItem "Charlie"
ListBox1.AddItem "Delta"
ListBox1.AddItem "Echo"
ListBox1.MultiSelect = fmMultiSelectMulti
End Sub
 
Last edited:
Upvote 0
Assuming You now have a listbox on your Userform try this''
And assuming your Listbox is name ListBox1

And since you never answered how you want the values entered this script does it two different ways

It will enter values in "D4" and "G4"

Modify the script to your needs.


One enters the values horizontally the other vertically

You can choose more then one value from the listbox

And my button that runs this script is named CommandButton1

Code:
Private Sub CommandButton1_Click()
Dim i As Long
   
    For i = 0 To ListBox1.ListCount - 1
        If ListBox1.Selected(i) Then
            Range("D4").Value = Range("D4").Value & ListBox1.List(i) & vbNewLine
            Range("G4").Value = Range("G4").Value & ListBox1.List(i) & " "
        End If
    Next
End Sub
Private Sub UserForm_Initialize()
ListBox1.AddItem "Alpha"
ListBox1.AddItem "Bravo"
ListBox1.AddItem "Charlie"
ListBox1.AddItem "Delta"
ListBox1.AddItem "Echo"
ListBox1.MultiSelect = fmMultiSelectMulti
End Sub

Perfect Thank you.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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