+ Reply to Thread
Results 1 to 5 of 5

Help with userform code, please?

  1. #1
    Forum Contributor
    Join Date
    11-14-2007
    Posts
    142

    Help with userform code, please?

    Hi I am not experienced in VBA so please if possible respond in context.
    I have a workbook with a globally defined named range "MyArray" which refers to a constant array = {"Item1","Item2","Item3"}
    My general module contains the following

    Please Login or Register  to view this content.
    UserForm1 contains just four objects:
    CommandButton1 displays "OK"
    CommandButton2 displays "Cancel"
    ComboBox1
    Label1 describes ComboBox1

    What I am trying to achieve is this:
    If at any time the user clicks "Cancel", the UserForm1 is unloaded and bResponse is returned False. Otherwise:
    User clicks the dropdown arrow on the ComboBox and a list appears containing the values in MyArray.
    User selects a value from that drop down list and confirms by clicking "OK".
    That newly selected value is then assigned to the variable sComboVal
    And then the routine in the general module that called the userform undertakes various actions based on the newly assigned value of sComboVal.

    So far, all I have managed to achieve in the code behind the userform is to define what happens when the user clicks OK or cancel, thus:

    Please Login or Register  to view this content.
    At this point I get lost, that is to say programming the code for the ComboBox1,
    (a) so that it lists the values of MyArray, and
    (b) to assign to sComboVal the value selected from that list by the user.

    Can someone please help me with these last steps (and correct any obvious errors so far)?

    Thanks
    Last edited by 1eyedjack; 02-19-2010 at 09:11 AM.

  2. #2
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Help with userform code, please?

    Your post does not comply with the Forum Rules you agreed to follow. Per Rule #3, all VBA code must be wrapped in code tags. Please edit your thread to apply the code tags, after which solutions to your question will be suggested.

    Rule #3
    Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # button at the top of the post window. If you are editing an existing post, press Go Advanced to see the # button. For more information about these and other tags, click here.
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  3. #3
    Forum Contributor
    Join Date
    11-14-2007
    Posts
    142

    Re: Help with userform code, please?

    Done, with apologies and thanks for any help

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,983

    Re: Help with userform code, please?

    Roughly speaking:

    Normal module:
    Please Login or Register  to view this content.
    Userform module:
    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Forum Contributor
    Join Date
    11-14-2007
    Posts
    142

    Re: Help with userform code, please?

    Beautiful, thanks

+ 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