ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Get value from combobox (https://www.excelbanter.com/excel-programming/332245-get-value-combobox.html)

Bruce

Get value from combobox
 
I am trying to get a value from my a combobox on my sheet "Update" but it
tells me object required.

What have I missed?


Function myRegion
Dim cb_region As ComboBox

With Sheets("Update")
myRegion = cb_region.Value
End With
End Function


Edwin Tam[_7_]

Get value from combobox
 
I think, from your question, your combobox is placed on a worksheet called
"Update". Also, I assume you have already given it a name "cb_region".

On a worksheet, a combo Box is a "DropDown" object in Excel's object
library. Also, you need to be careful with statements between the "With" and
"End With". You seemed to missed the dot (period).

I've modified your macro as follows:

Function myRegion()
Dim myRegion
With Sheets("Update")
myRegion = .DropDowns("cb_region").Value
End With
End Function

(Again, as I've mentioned, I assume you have already assigned a name to your
combo box. If not, please give it the name "cb_region".)

Regards,
Edwin Tam

http://www.vonixx.com



"Bruce" wrote:

I am trying to get a value from my a combobox on my sheet "Update" but it
tells me object required.

What have I missed?


Function myRegion
Dim cb_region As ComboBox

With Sheets("Update")
myRegion = cb_region.Value
End With
End Function


JMB

Get value from combobox
 
is the name of your combobox on Update sheet named cb_region? if so, you
don't need to declare it as a variable. Since you are only performing one
command, you can eliminate With/End With and just use

myRegion = Sheets("Update").cb_region.Value


"Bruce" wrote:

I am trying to get a value from my a combobox on my sheet "Update" but it
tells me object required.

What have I missed?


Function myRegion
Dim cb_region As ComboBox

With Sheets("Update")
myRegion = cb_region.Value
End With
End Function



All times are GMT +1. The time now is 04:23 PM.

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