Consulting

Results 1 to 4 of 4

Thread: UF ComboBox Populate from Sheet

  1. #1
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location

    UF ComboBox Populate from Sheet

    I have a userform with Radio buttons. I want to be able to click on a radio button then have it populate a combobox based on what radio button is selected.
    So if
    OptButtonHP.value = True Then
    
    cmbboxModel.additem = sheet("Lists").Range("A2:A"), Cells(Row.Count, "A").End(xlUp)

    If another radiobutton is selected that range would change to ("B2:B")....

    Any assistance would be great.

    Thanks,

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,021
    probably something along the lines of:
    Private Sub OptButtonHP_Change()
    With Sheets("Lists")
      If OptButtonHP Then
        cmbboxModel.List = .Range("A2", .Cells(.Rows.Count, "A").End(xlUp)).Value
      Else
        cmbboxModel.List = .Range("B2", .Cells(.Rows.Count, "B").End(xlUp)).Value
      End If
    End With
    End Sub
    or:
    Private Sub OptButtonHP_Change()
    With Sheets("Lists")
      If OptButtonHP Then
        cmbboxModel.RowSource = .Range("A2", .Cells(.Rows.Count, "A").End(xlUp)).Address(external:=True)
      Else
        cmbboxModel.RowSource = .Range("B2", .Cells(.Rows.Count, "B").End(xlUp)).Address(external:=True)
      End If
    End With
    End Sub
    p45cal - - - - -This is my signature, it appears after all my posts. Below is not directed at anyone in particular - so don't take offence! - (You might guess why it's there though)
    If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Knowledge Base Approver VBAX Guru
    Joined
    Apr 2012
    Posts
    4,893
    Private Sub OptButtonHP_Change() 
       cmbboxModel.List = Sheets("Lists").columns(1).specialcells(2).offset(1).specialcells(2).value 
    End Sub 
    
    Private Sub OptButtonHQ_Change() 
       cmbboxModel.List = Sheets("Lists").columns(2).specialcells(2).offset(1).specialcells(2).value 
    End Sub

  4. #4
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    That worked. Thanks

Posting Permissions

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