ComboBox returns only index number - I want it to return the text

SashaFromSydney

New Member
Joined
Dec 3, 2014
Messages
1
Hi all,

newbie here with excel 2010 macro: created a combobox (from under 'form controls'), the purpose of which is that the user makes a selection which then populates the active cell (ie the cell the user highlighted before making the selection from the combobox). The population should happen upon click event.

I have managed to achieve this, however the code (below) populates the active cell with the index number of the selected entry (e.g. if user chooses first entry from combobox, the active cell is populated with a "1"), however I want the actual selection text to populate the active cell.

Help appreciated.

Sub Combobox1_UserClick()
Dim sht As Worksheet
Dim mycell As Range
worksheets("unit decision").Activate
'mycell = Application.worksheets("unit decision").ActiveCell
Set sht = Application.worksheets("unit decision")
ActiveCell.Value = sht.Shapes("ComboBox1").ControlFormat.Value
'If ComboBox1.ListIndex <> -1 Then
'ActiveSheet.ActiveCell.Value = worksheets("Sheet2").ComboBox1.Text
'End If
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Welcome to the forum. Please use code tags when posting code (it's the # button)
Your code returns the ControlFormat.Value not the combobox text.
Try:
Code:
Sub Combobox1_UserClick()Dim sht As Worksheet
Dim mycell As Range
worksheets("unit decision").Activate
'mycell = Application.worksheets("unit decision").ActiveCell
Set sht = Application.worksheets("unit decision")
ActiveCell.Value = sht.Shapes("ComboBox1").Value ' OR sht.Shapes("ComboBox1").text
'If ComboBox1.ListIndex <> -1 Then
'ActiveSheet.ActiveCell.Value = worksheets("Sheet2").ComboBox1.Text
'End If
End Sub
Dan
 
Upvote 0

Forum statistics

Threads
1,215,767
Messages
6,126,767
Members
449,336
Latest member
p17tootie

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