VBA listbox value to cell

Faygin

New Member
Joined
May 12, 2020
Messages
23
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I initialize a userform and a listbox with different types of options like this:
---
VBA Code:
Private Sub UserForm_Initialize()

ArrayPrimarEmb = Array("-- Ange Alternativ --", "Kit", "Rund Tub", "Platt Tub", "Oval Tub", "Glasflaska", "Fyrkantig Flaska", "Oval Flaska", "Rund Flaska", "Burk", "Tunna med Lock", "Plastdunk", "Sachee Förpackning")

PrimarEmb.List = ArrayPrimarEmb

End Sub
---

Then when button is pressed i want to put the selected alternative in text in my worksheet.
---
VBA Code:
Private Sub CommandButton1_Click()

Cells(1, "E").Value = PrimarEmb.Value

End Sub
---

But that doesnt work.
How do i get the actual selected "item" in my workbook?
Thank you for your help!
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi Faygin,

code works fine for me in a sample workbook. Do you get any error messages?

Ciao,
Holger
 
Upvote 0
Is you listbox set to single select or multi select?
 
Upvote 0
Hi Holger.
I dont get any error messages, its just dont transfer any data, the recieving cell is blank.

Hi Fluff
0-fmMultiselectSingle is the setting.
 
Upvote 0
In that case the code should work & put the listbox value into E1 on the active sheet.
 
Upvote 0
ArrayNotWorking.JPG

Rich (BB code):
Private Sub CommandButton1_Click()




Cells(1, "A").Value = ArtikelnummerFV.Value
Cells(1, "B").Value = Benamning.Value
Cells(1, "C").Value = Tillverkningsstorlek.Value
Cells(1, "D").Value = KalkylKvant.Value
Cells(1, "E").Value = PrimarEmb.Value


End Sub



Private Sub UserForm_Initialize()


ArrayPrimarEmb = Array("-- Ange Alternativ --", "Kit", "Rund Tub", "Platt Tub", "Oval Tub", "Glasflaska", "Fyrkantig Flaska", "Oval Flaska", "Rund Flaska", "Burk", "Tunna med Lock", "Plastdunk", "Sachee Förpackning")

PrimarEmb.List = ArrayPrimarEmb

End Sub

Very frustrating but cant get the red parts to work. All other information gathered from TextBoxes works just fine and displays in A, B, C, D.
The "E" part isnt working.
 
Last edited by a moderator:
Upvote 0
Do you get any error messages?
 
Upvote 0
No error messages, all other cells fills just fine.
 
Upvote 0
Problem solved! Changed to a ComboBox and now it works fine. Thank you for your time Fluff & HaHoBe, greatly appreciated.
 
Upvote 0
Solution
Glad you sorted it & thanks for letting us know.
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,665
Members
449,091
Latest member
peppernaut

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