+ Reply to Thread
Results 1 to 15 of 15

Selecting an Item in a ComboBox with a List Created from RowSource

  1. #1
    Registered User
    Join Date
    01-08-2013
    Location
    Stafford
    MS-Off Ver
    Excel 2003
    Posts
    10

    Selecting an Item in a ComboBox with a List Created from RowSource

    I've got a combo box which is populated from column A from sheet 1. I am linking each item in that combobox to a Macro. I don't want to hardcode it like this....

    If ComboBox1.Text = "Early Years" Then Call EarlyYears

    Is there a way I can link it from the cell it came from.....so for example "Early Years" came from A8. Incase that title changes I want the coding to be flexible and accommodate that change.

    Can anyone help?

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Selecting an Item in a ComboBox with a List Created from RowSource

    Maybe:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-08-2013
    Location
    Stafford
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Selecting an Item in a ComboBox with a List Created from RowSource

    But wouldn't I still have to put the text "Early Years"? I want to be able to refer to the "Early Years" cell A8.

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Selecting an Item in a ComboBox with a List Created from RowSource

    I though that you were just trying to run a macro that has the same name as the selected item in your ComboBox, is that not what you're trying to do?

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Selecting an Item in a ComboBox with a List Created from RowSource

    I'm not clear on what you are trying to do but maybe:

    Please Login or Register  to view this content.
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  6. #6
    Registered User
    Join Date
    01-08-2013
    Location
    Stafford
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Selecting an Item in a ComboBox with a List Created from RowSource

    No sorry perhaps I didn't explain well enough. I have a combo box that I've got a list in which has come from a table in an excel sheet. I want to link each item in the list to a macro, but in the code I don't want to refer to the text in the combo box (ie. early years) as this might change in the future but instead want to refer to the cell that each item is in (ie. A8). If I put the text in the code then I will always be changing the code. Want it to be more flexible.

  7. #7
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Selecting an Item in a ComboBox with a List Created from RowSource

    That's what mine does (I think ) it runs a macro that has the same name as the selected item in the combobox.

  8. #8
    Registered User
    Join Date
    01-08-2013
    Location
    Stafford
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Selecting an Item in a ComboBox with a List Created from RowSource

    The macro's don't have the same name as the item in the combobox.
    I have a list of project in column A: ie.

    Column A
    Project A
    Project B
    Project C

    The combo box list has been generated from this column. The projects will change or be removed so the list in the combobox will change.

    The code I've used currently is:

    ComboBox1.Text = "Project A" Then Call ProjectA (although the macros have the same name for this they don't all and won't in the future if the project changes in Column A)

    So because the list will change I don't want to reference "Project A" (in red above) in the code instead

  9. #9
    Registered User
    Join Date
    01-08-2013
    Location
    Stafford
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Selecting an Item in a ComboBox with a List Created from RowSource

    Oops sent that too soon.

    ...in the code instead I want to reference the cell that "Project A" is in, that way if it changes to "Project G" the programme will still work.

  10. #10
    Registered User
    Join Date
    01-08-2013
    Location
    Stafford
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Selecting an Item in a ComboBox with a List Created from RowSource

    Oops sent that too soon.

    ...in the code instead I want to reference the cell that "Project A" is in, that way if it changes to "Project G" the programme will still work.

  11. #11
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    818

    Re: Selecting an Item in a ComboBox with a List Created from RowSource

    Maybe this is a way if I understood the question correctly.
    Please Login or Register  to view this content.
    In standardmodul.
    Please Login or Register  to view this content.
    Kind regards, Harry.

  12. #12
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Selecting an Item in a ComboBox with a List Created from RowSource

    So you want to always run the same macro for the first item in the list, the second macro for the second item in the list and third macro for the third item in the list etc. regardless of the text in combobox? If that's the case you can use HSVs code if the macros are numerically incremented.

  13. #13
    Registered User
    Join Date
    01-08-2013
    Location
    Stafford
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Selecting an Item in a ComboBox with a List Created from RowSource

    So is "HSV" the macro?
    And is ListIndex + 1 the first cell A1? So would Cell A2 be ListIndex +2?

  14. #14
    Registered User
    Join Date
    01-08-2013
    Location
    Stafford
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Selecting an Item in a ComboBox with a List Created from RowSource

    Kyle, yeah that's right. Could someone explain what HSV is please?

  15. #15
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    818

    Re: Selecting an Item in a ComboBox with a List Created from RowSource

    Here is an example shona.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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