Check if combobox has assigned value

always_confused

Board Regular
Joined
Feb 19, 2021
Messages
68
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I am using the value selected in a combobox as a sort of filter, as in
VBA Code:
If Range("A1")=ActiveSheet.OLEObjects("ComboBox1").Object.Value Then 
Range("B1") = Range("A1").value/ ActiveSheet.OLEObjects("ComboBox1").Object.Value

However if ActiveSheet.OLEObjects("ComboBox1").Object.Value is not assigned, I'm dividing by nothing and that doesn't work. I have tried a bunch of combinations of Is Null, is Nothing etc, and I cannot figure out how to check if the value has been selected in the combobox before dividing by it.

Can anyone help me with the syntax here?
Thanks
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
When you created an ActiveX (ComboBox in this case), the default assigned name is ComboBox1, subsequent one will be ComboBox2, ComboBox3 and so on. This is shown in Name Box (the box left to the formula bar) when you select the ComboBox in Design Mode (for example).
You can simple refer to the object by its name just like this
ComboBox1.Value -- will give the value selected. If nothing is selected, I believe it will just be blank.

Let say you refer to a range for drop down value and it is number 1, 2, and3.
Range("A1") = ComboBox1.Value
will results in "1" (text) if number 1 is selected, but I believe it will still converted to number by Excel if you put say
Range("C1") = 3 / Range("A1")

You can check if ComboBox has any value using
If Not Len(ComboBox1.Value)=0
 
Upvote 0
Solution
When you created an ActiveX (ComboBox in this case), the default assigned name is ComboBox1, subsequent one will be ComboBox2, ComboBox3 and so on. This is shown in Name Box (the box left to the formula bar) when you select the ComboBox in Design Mode (for example).
You can simple refer to the object by its name just like this
ComboBox1.Value -- will give the value selected. If nothing is selected, I believe it will just be blank.

Let say you refer to a range for drop down value and it is number 1, 2, and3.
Range("A1") = ComboBox1.Value
will results in "1" (text) if number 1 is selected, but I believe it will still converted to number by Excel if you put say
Range("C1") = 3 / Range("A1")

You can check if ComboBox has any value using
If Not Len(ComboBox1.Value)=0
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

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