+ Reply to Thread
Results 1 to 7 of 7

Userform: Set Combobox.Value on "Change" of a different Combobox

Hybrid View

  1. #1
    Registered User
    Join Date
    09-15-2012
    Location
    Oklahoma
    MS-Off Ver
    Office 2010
    Posts
    8

    Userform: Set Combobox.Value on "Change" of a different Combobox

    I am attempting to change the value of Combobox2 when Combobox1 is changed.
    Here is what I have.

    Sub Combobox1_Change ()
    
    Combobox2.Value = "(Select)"
    
    End Sub
    I am returned an error stating:

    "Run-Time error '380': Could not set the Value property. Invalid property value."
    When I remove the (Select) string and just set the .Value = "" it will run the code but I want to set the value of the combobox to Value not blank ("")

    It should be noted that I am using a Userform_Initialize sub which is pre-populating the values of all Comoboxes on the Userform including Comboboxes1 and 2.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Userform: Set Combobox.Value on "Change" of a different Combobox

    I do not get that error.

    
    
    Private Sub UserForm_Activate()
    ComboBox1.Value = "(Select)"
    End Sub
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,346

    Re: Userform: Set Combobox.Value on "Change" of a different Combobox

    You can just set the listindex to the correct value - for example, if "(Select)" is the first value in the list

    Private Sub UserForm_Initialize()
    'other code here
    Me.ComboBox2.List = Array("(Select)", "whatever 1", "whatever 2", "whatever 3", "whatever 4")
    End Sub
    
    Private Sub ComboBox1_Change()
    Me.ComboBox2.ListIndex = 0
    End Sub
    Last edited by Bernie Deitrick; 12-10-2015 at 06:01 PM.
    Bernie Deitrick
    Excel MVP 2000-2010

  4. #4
    Registered User
    Join Date
    09-15-2012
    Location
    Oklahoma
    MS-Off Ver
    Office 2010
    Posts
    8

    Re: Userform: Set Combobox.Value on "Change" of a different Combobox

    Quote Originally Posted by Bernie Deitrick View Post
    You can just set the listindex to the correct value - for example, if "(Select)" is the first value in the list

    Private Sub UserForm_Initialize()
    'other code here
    Me.ComboBox2.List = Array("(Select)", "whatever 1", "whatever 2", "whatever 3", "whatever 4")
    End Sub
    
    Private Sub ComboBox1_Change()
    Me.ComboBox2.ListIndex = 0
    End Sub
    The "(Select)" value I am pushing into the combobox is not a selection from the drop down array listing.
    It is meant as an initial forced value into the box to prompt the user to click it and select from the drop down options.

    I am trying to set the value of the box as you would with an Initialize userform sub

    Quote Originally Posted by Norie View Post
    Have you set the MatchRequired property of ComboBox2 to True?
    Yes, still no luck

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Userform: Set Combobox.Value on "Change" of a different Combobox

    Have you set the MatchRequired property of ComboBox2 to True?
    If posting code please use code tags, see here.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Userform: Set Combobox.Value on "Change" of a different Combobox

    I'm not suggesting you set MatchRequired to True, in fact if you have it set to True that's the reason you get the error you describe.

  7. #7
    Registered User
    Join Date
    09-15-2012
    Location
    Oklahoma
    MS-Off Ver
    Office 2010
    Posts
    8

    Re: Userform: Set Combobox.Value on "Change" of a different Combobox

    It was set to False at the start. I changed it back.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. = EMBED("Forms.ComboBox.1","") error "Reference not valid."
    By CatharinaCatharina in forum Excel General
    Replies: 2
    Last Post: 12-11-2014, 09:58 AM
  2. Userform Combobox to populate form: Can I change the order of the columns in the combobox?
    By CraigWiggins in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-31-2014, 12:14 PM
  3. VBA change pivot "report filter" from userform textbox or combobox
    By mmor79 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-11-2014, 12:57 PM
  4. VBA: "Un"-Dropdown a Combobox in a Userform
    By BigBas in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-13-2012, 12:41 AM
  5. Replies: 1
    Last Post: 04-07-2012, 04:36 PM
  6. Userform: Make a advanced filter script "filter" when a combobox is altered
    By Zheno in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-09-2010, 04:06 AM
  7. [SOLVED] EMBED("Forms.ComboBox.1","")
    By augustus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-01-2005, 11:06 AM

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