+ Reply to Thread
Results 1 to 5 of 5

Problem in Variable Scope

  1. #1
    vrk1
    Guest

    Problem in Variable Scope

    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?

  2. #2
    Vasant Nanavati
    Guest

    Re: Problem in Variable Scope

    Try:

    MsgBox Sheet1.cbovar

    And use "Option Explicit"!

    --

    Vasant



    "vrk1" <[email protected]> wrote in message
    news:[email protected]...
    > 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?



  3. #3
    vrk1
    Guest

    Re: Problem in Variable Scope

    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

    "Vasant Nanavati" wrote:

    > Try:
    >
    > MsgBox Sheet1.cbovar
    >
    > And use "Option Explicit"!
    >
    > --
    >
    > Vasant
    >
    >
    >
    > "vrk1" <[email protected]> wrote in message
    > news:[email protected]...
    > > 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?
    >
    >
    >


  4. #4
    Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    481
    where do you have the value of cbovar assigned?
    and where have you placed your macroa subroutine?

    Try the following, perhaps this is what you are looknig for.

    In the worksheet module place:

    Option Explicit

    Private Sub ComboBox1_Change()
    cbovar = ComboBox1.Value
    End Sub

    Private Sub CommandButton1_Click()
    macroa
    End Sub


    now in a general module place

    Option Explicit
    Public cbovar As String

    Sub macroa()
    MsgBox (cbovar)
    End Sub


    Hopefully this is what you are trying to do and helps.

  5. #5
    Vasant Nanavati
    Guest

    Re: Problem in Variable Scope

    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.

    --

    Vasant

    "vrk1" <[email protected]> wrote in message
    news:[email protected]...
    > 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
    >
    > "Vasant Nanavati" wrote:
    >
    > > Try:
    > >
    > > MsgBox Sheet1.cbovar
    > >
    > > And use "Option Explicit"!
    > >
    > > --
    > >
    > > Vasant
    > >
    > >
    > >
    > > "vrk1" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > 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?
    > >
    > >
    > >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1