Problem in Variable Scope

G

Guest

I have a Combobox (cbovar) inside the Worksheet "Sheet1" I also have a
Submit button that calls a macro "Macro A" (Note: There are no Userforms
here. The buttons are in the worksheet "sheet1".)

The function of "Macro A" is to show the value of the combobox.

sub macroa
msgbox(cbovar)
end sub


The value shows up blank even when the combobox is checked on "Sheet1".

How do I get the value of the combobox printed on the screen? I am having
problem understanding "variable scope" ...Can anyone help me out here please?
 
V

Vasant Nanavati

Try:

MsgBox Sheet1.cbovar

And use "Option Explicit"!

--

Vasant



vrk1 said:
I have a Combobox (cbovar) inside the Worksheet "Sheet1" I also have a
Submit button that calls a macro "Macro A" (Note: There are no Userforms
here. The buttons are in the worksheet "sheet1".)

The function of "Macro A" is to show the value of the combobox.

sub macroa
msgbox(cbovar)
end sub


The value shows up blank even when the combobox is checked on "Sheet1".

How do I get the value of the combobox printed on the screen? I am having
problem understanding "variable scope" ...Can anyone help me out here
please?
 
G

Guest

That did not work. I am getting a Run Time Error message.

Maybe I am doing something wrong. Can you explain with a code please?

Thanks
 
V

Vasant Nanavati

Is cbovar a ComboBox from the Forms Toolbar or the Control Toolbox? If the
former, you cannot directly retrieve its value; you have to look it up from
the source range.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top