Listbox userform, multiple values into same cell.

freddie mitchell

New Member
Joined
Apr 14, 2011
Messages
43
Hello lovely people,

With great help from hero member Fluff, I've got a code that adds values entered into a listbox by a user. This code is perfect at putting multiple values into multiple cells. For example, value X, Y, Z go into cells A1, A2 and A3.

However, can anyone help me change this code so that multiple values can be put into one cell. For example, value X, Y, Z all go into cell A1.
Below is my abortive attempt to modify Fluff's code for entering values into one cell. As it stands, if the user selects either "peanut" or "hazelnut" then they will appear in cell 4. But if the user selects both peanut and hazelnut then only hazelnut will appear in the cell.


VBA Code:
Dim h As Long
With Me.allergylist
    For h = 0 To .ListCount - 1
    If .Selected(h) Then
    Select Case .List(h)
                Case "peanuts"
                Cells(r, 4).Value = Cells(r, 5).Value & "peanuts"
                Case "hazelnuts"
                Cells(r, 4).Value = Cells(r, 5).Value & "hazelnuts"
               
End Select
End If
Next h
End With
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try this:

VBA Code:
  Dim h As Long
  With Me.allergylist
    For h = 0 To .ListCount - 1
      If .Selected(h) Then
        Select Case .List(h)
          Case "peanuts", "hazelnuts"
            Cells(r, 4).Value = Cells(r, 4).Value & .List(h) & " "
        End Select
      End If
    Next h
  End With
 
Upvote 0
Solution

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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