ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Capture Current Selection in a Combo Box (https://www.excelbanter.com/excel-programming/306194-capture-current-selection-combo-box.html)

Randy[_10_]

Capture Current Selection in a Combo Box
 
Hi,

I'm trying capture the current selection from a combo box (from the
Control Toolbox, not Forms). Example:

MySelection = ComboBox1.Value

I don't know how to refer to the combo box. I'm getting a compile
error (variable not defined). Please note, I am not working in the
private subroutine. I am working outside of the combo box code in a
general module.

TIA
Randy Eastland

cmart02[_2_]

Capture Current Selection in a Combo Box
 
If you're working on a module, you need to refer to the combobox in its
container (form). So if your form is called UserForm1 you would have
something like this:

MySelection = UserForm1.ComboBox1.Value

Also if you're using Option Explicit at the top of your code, you need to
declare the dimension of MySelection.


Greg Wilson[_4_]

Capture Current Selection in a Combo Box
 
Assuming you meant a worksheet based ComboBox from the
Control Toolbox toolbar:

Sub GetComboValue()
Dim txt As String
txt = ActiveSheet.OLEObjects("ComboBox1").Object.Value
MsgBox txt
End Sub

Regards,
Greg

-----Original Message-----
Hi,

I'm trying capture the current selection from a combo box

(from the
Control Toolbox, not Forms). Example:

MySelection = ComboBox1.Value

I don't know how to refer to the combo box. I'm getting a

compile
error (variable not defined). Please note, I am not

working in the
private subroutine. I am working outside of the combo

box code in a
general module.

TIA
Randy Eastland
.


Randy[_10_]

Capture Current Selection in a Combo Box
 
Thanks, Greg. Exactly what I needed to know.

(Randy) wrote in message . com...
Hi,

I'm trying capture the current selection from a combo box (from the
Control Toolbox, not Forms). Example:

MySelection = ComboBox1.Value

I don't know how to refer to the combo box. I'm getting a compile
error (variable not defined). Please note, I am not working in the
private subroutine. I am working outside of the combo box code in a
general module.

TIA
Randy Eastland



All times are GMT +1. The time now is 07:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com