Results 1 to 2 of 2

Thread: Toggle Between RowSource Items And List Items In A ComboBox Based On Criteria

  1. #1
    Junior Member
    Join Date
    Mar 2018
    Posts
    12
    Rep Power
    0

    Lightbulb Toggle Between RowSource Items And List Items In A ComboBox Based On Criteria

    Hi All,
    I have a small problem. Attached a small spreadsheet.

    I have a form with two combo boxes. The row sources are “Languages” and “Levels”

    Some of the languages have a “*” on the right of the string.

    When I select a language, the second column is also populated.

    When I select languages with “*” at the right of the string, I want only "Lower" is the only level can be selected.

    Code:
    Private Sub CommandButton1_Click()
    Dim eRow As Long
        eRow = Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
        Sheets("Sheet2").Activate  
        Cells(eRow, 1) = ComboBox1.Text
        Cells(eRow, 2) = ComboBox1.Column(1)
        If Right(ComboBox2.Text, 1) = "*" Then
            ComboBox2.RowSource = Sheets("Sheet2").Range("E2")
        Else
            ComboBox2.RowSource = "Levels"
        End If
        Cells(eRow, 3) = ComboBox2.Text
        ComboBox1.Text = ""
        ComboBox2.Text = "”
    End Sub

    Any help with editing the code will be helpful.

    Thank you

    Raghavendra
    Attached Files Attached Files

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    One way to do that is given below. Just replace your existing code with it.

    Code:
    Private Sub ComboBox1_Change()
        
        With ComboBox2
            If Right(ComboBox1.Text, 1) = "*" Then
                .RowSource = ""
                .List = Array("Lower")
                .Value = "Lower"
            Else
                .RowSource = "Levels"
                .ListIndex = -1
            End If
        End With
        
    End Sub
    
    Private Sub CommandButton1_Click()
        
        Dim eRow As Long
        
        With Sheets("Sheet2")
            eRow = .Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0).Row
            .Cells(eRow, 1).Resize(, 3).Value = Array(ComboBox1.Text, ComboBox1.Column(1), ComboBox2.Text)
            .Activate
        End With
        
    End Sub
    
    Private Sub CommandButton2_Click()
        Application.Quit
    End Sub
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

Similar Threads

  1. Replies: 3
    Last Post: 10-11-2013, 02:52 PM
  2. Replies: 10
    Last Post: 08-29-2013, 08:20 PM
  3. Replies: 8
    Last Post: 08-17-2013, 04:03 AM
  4. Replies: 25
    Last Post: 08-02-2013, 07:23 AM
  5. Replies: 14
    Last Post: 06-27-2013, 10:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •