+ Reply to Thread
Results 1 to 5 of 5

Form control combo box

Hybrid View

copernicus Form control combo box 10-28-2017, 04:09 AM
AlphaFrog Re: Form control combo box 10-28-2017, 04:55 AM
copernicus Re: Form control combo box 10-28-2017, 05:51 AM
AlphaFrog Re: Form control combo box 10-28-2017, 06:31 AM
mehmetcik Re: Form control combo box 10-28-2017, 06:14 AM
  1. #1
    Registered User
    Join Date
    06-16-2009
    Location
    Irvine, CA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Form control combo box

    3 questions about combo boxes (form control not activex)

    I have combobox1 that references a column with 9 entries. Depending on the value in a cell some of those entries may be blanked out because they are invalid. The usable cells are contiguous. Eg the column has A B C D E F G H I . if cell a1 is 4, A B C are blanked out, D E F G H I are valid. A blank cell could of course be erroneously selected and need correction. Is there a better way to handle dynamically changing the valid entries in a combo box or other control?

    Once I have selected from the valid entries (in whatever the best method is) from the first selection I would like to default a similar combobox2 to one of its valid values, which has blanked out values based on the combobox1 selection.

    Finally I would like to have a separate "advance" mechanism. Eg clicking on a cell advances the selection in the first combo box to the next lower entry in the valid list, or the top of the list if its at the bottom. What is the best way to handle that?

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Form control combo box

    It would be easier if you attached an example workbook.

    The Worksheet_Change procedure will repopulate Drop Down 1 when you make a change to cell A1. It loops through cells B1:B9 and adds items excluding blanks. A similar code block could be added to the procedure for a additional drop downs.

    The Worksheet_SelectionChange procedure will "Advance" the drop down selection to the next item when you select cell D1.

    To install the code:
    • Right-click on the sheet tab.
    • Select View Code from the pop-up context menu.
    • Paste the code from below in the worksheet's code module.

    Private Sub Worksheet_Change(ByVal Target As Range)
        'Populate excluding blanks
        Dim dd As DropDown, cell As Range
        If Target(1).Address(0, 0) = "A1" Then
            Set dd = Me.DropDowns("Drop Down 1")
            dd.ListFillRange = ""
            dd.RemoveAllItems
            For Each cell In Range("B1:B9")
                If cell <> "" Then dd.AddItem cell.Value
            Next cell
        End If
    End Sub
    
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        'advance
        Dim dd As DropDown, ndx As Long
        If Target(1).Address(0, 0) = "D1" Then
            Set dd = Me.DropDowns("Drop Down 1")
            ndx = dd.ListIndex
            If ndx = dd.ListCount Then ndx = 1 Else ndx = ndx + 1
            dd.ListIndex = ndx
        End If
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    06-16-2009
    Location
    Irvine, CA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Form control combo box

    Thanks. I think I understand whats going on and how to modify it, but Im getting a compile error "invalid use of me keyword". I placed your code in Module 1. Wrong place?

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Form control combo box

    Quote Originally Posted by copernicus View Post
    Thanks. I think I understand whats going on and how to modify it, but Im getting a compile error "invalid use of me keyword". I placed your code in Module 1. Wrong place?
    Yes, wrong place. See the "To install the code" instructions in the post.

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

    Re: Form control combo box

    AlphaFrog's Macro is sheet specific.

    Right Click on the sheet name at the bottom of excel and select view code.

    Paste the code into the module that opens and close it.
    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.

+ 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. Two Combo Boxes (Form Control) depending on each other
    By esbencito in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 09-22-2017, 01:25 AM
  2. How to add currency Combo Box form control
    By blackcode82 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-18-2016, 09:02 AM
  3. Code works with Combo Box-Form Control, but not with Combo box - ActiveX Control
    By nangys in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-01-2014, 08:51 AM
  4. [SOLVED] Form Control Combo Box Selection
    By wacky_diva in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-22-2013, 08:31 PM
  5. Resetting a form control combo box without using VBA
    By Chris Shepherd in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-22-2013, 10:47 PM
  6. [SOLVED] Want to combine 8 separate form control to a combo box
    By kamaaina in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-11-2013, 12:39 AM
  7. [SOLVED] Hide Rows With Combo Box (Form Control)
    By needexcelhelp123 in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 09-13-2012, 04:10 PM

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