+ Reply to Thread
Results 1 to 18 of 18

.Find to ComboBox (VBA Code Only)

  1. #1
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    .Find to ComboBox (VBA Code Only)

    I have a list of values in Column A that are sometimes the same, but their corresponded data in Column B will be different. In these instances I want the values in Column B to be entered into a Combo/ListBox for user selection of the appropriate value.

    I have attached the spreadsheet, but I have not written the code because I am not sure how to yet.

  2. #2
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: .Find to ComboBox (VBA Code Only)

    If you want transfer column "B" to a combobox/listbox, you can do it like so:

    Please Login or Register  to view this content.
    Rename: Worksheets

  3. #3
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: .Find to ComboBox (VBA Code Only)

    Well I want to combine it with code similar to this

    Please Login or Register  to view this content.
    so that when the .Find/.FindNext for Column A has mutiple results the value in Column B that corresponds to Column A is in a list...

  4. #4
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: .Find to ComboBox (VBA Code Only)

    For what it is worth, I understand VBA much better than I understand Excel & Excel Formulas, so your example is lost on me.

  5. #5
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: .Find to ComboBox (VBA Code Only)

    Let me see if I can explain this better...

    I have two comlumns of data. Column A and Column B. Each has (for example 10 rows). Column A has 7 values but 10 rows as 1 value is repeated 4 times. Column B has 10 unique values in each row. So I need to use .Find/.FindNext on Column A to populate a ListBox of the Values of Column B only where the value in Column A is repeated.

    ...A B
    1 A Alpha
    2 B Beta
    3 C Gamma
    4 C Delta
    5 D Epsilon
    6 E Zeta
    7 C Theta
    8 C Pi
    9 F Mu
    10 G Omega

    So where the .Find sees C it populates the ListBox with Gamma, Delta, Theta, Pi

  6. #6
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: .Find to ComboBox (VBA Code Only)

    Unless I'm missing something, your example spreadsheet is already sorted in that order.

    So is the problem that your spreadsheet will not always be sorted by column A?

    Or is the problem that you need to know how to add two columns to a combobox/listbox?

    Or both?

  7. #7
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: .Find to ComboBox (VBA Code Only)

    The sort of Column A is irrelevant.

    I just want a Combo/List Box using values from Column B if the corresponding value in Column A has more than 1 instance.

  8. #8
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: .Find to ComboBox (VBA Code Only)

    maybe something like
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: .Find to ComboBox (VBA Code Only)

    Nilem,

    Created userform with listbox1.

    where do I put the code?

  10. #10
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: .Find to ComboBox (VBA Code Only)

    In the form module.
    Usually create two listboxes: the first is filled with unique values ​​from column A in the form initialization procedure, and the second listbox is populated in the change the first listbox procedure.

  11. #11
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: .Find to ComboBox (VBA Code Only)

    I tried putting in the form. I couldn't get it to work. Would you mind uploading an example?

  12. #12
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: .Find to ComboBox (VBA Code Only)

    lloydgodin, attach your example with the form and I'll try to write code for you.

  13. #13
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: .Find to ComboBox (VBA Code Only)

    Here you go.

  14. #14
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: .Find to ComboBox (VBA Code Only)

    Press Alt+F8, run the 'test' macro. In the appeared form you can see the values ​​corresponding to the 'FEMUR'.
    Attached Files Attached Files

  15. #15
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: .Find to ComboBox (VBA Code Only)

    works like a charm. thanks.

  16. #16
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: .Find to ComboBox (VBA Code Only)

    This is more what I was trying to do. Although the variant S, I can't get from module 1 into the userform... it's not populating the list now.
    yes I know it'll be case specific, its not that...

  17. #17
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: .Find to ComboBox (VBA Code Only)

    try it (see attachment)
    Attached Files Attached Files

  18. #18
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: .Find to ComboBox (VBA Code Only)

    I made minor change to the code and now it's not working. I need the "data" entry part to be run from a different worksheet.

    Please Login or Register  to view this content.
    I am getting the error message. Methon 'Range' of object '_Worksheet' failed...
    Last edited by lloydgodin; 05-22-2012 at 12:06 PM. Reason: adding error message

+ 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