+ Reply to Thread
Results 1 to 5 of 5

Create combobox .list excluding some columns

Hybrid View

Hammer_757 Create combobox .list... 12-28-2012, 03:24 PM
jaslake Re: Create combobox .list... 12-28-2012, 05:13 PM
HSV Re: Create combobox .list... 12-28-2012, 05:51 PM
Hammer_757 Re: Create combobox .list... 12-28-2012, 06:14 PM
jaslake Re: Create combobox .list... 12-28-2012, 06:25 PM
  1. #1
    Forum Contributor
    Join Date
    03-21-2004
    Location
    Norwich, CT USA
    MS-Off Ver
    Excel 2010
    Posts
    163

    Create combobox .list excluding some columns

    I have a Combobox that is created based on a named range of column headings. Starting with the first column, every other column is titled “ (required) “. I do not want the “ (required) “ Headings in the Combobox. Any suggestions on how to do this?
    Problem area is in the last few lines few code

    Private Sub UserForm_Initialize()
    
    Dim lastRow As Integer
    Dim emplArr
    Dim frmTop As Integer
    Dim startRowCnt As Integer
    Dim endRowCnt As Integer
    Dim holder As String
    Dim chbxTmp As Control
    Dim topicRng As Range
    
    
     lastRow = Range(Range("b2"), Range("b2").End(xlDown)).Count + 1
    
      frmTop = 80
      emplArr = Range("B2:B" & lastRow)
      
      'list the names
      With lstAttendees
            .List = Range(Range("b2"), Range("b2").End(xlDown)).Value
            .ListStyle = fmListStyleOption
            .MultiSelect = fmMultiSelectMulti
      End With
    
      
      Me.Height = (lastRow - 5) * 20 + 180
        Me.ScrollHeight = Me.Height
      Me.Height = Me.Height * 0.5
      Me.ScrollBars = fmScrollBarsVertical
      
      'PROBLEM HERE
      'setup Topic Listbox
        Set topicRng = Range("topics")
        cbx_Topic_Choice.List = Application.WorksheetFunction.Transpose(topicRng)
    
    End Sub
    File attached if that helps.
    The code is initialized by the "Update Topics" button at the bottom of the data on the first worksheet.

    Thanks
    Robert
    Attached Files Attached Files

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Create combobox .list excluding some columns

    Hi Hammer_757
    Try this
    'setup Topic Listbox
        For Each topic In Range("topics")
            If Not topic.Value = "(Required)" Then
                With Me.cbx_Topic_Choice
                    .AddItem topic.Value
                End With
            End If
        Next topic
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

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

    Re: Create combobox .list excluding some columns

    Or:
    End With
    
      
      Me.Height = (lastRow - 5) * 20 + 180
      
      Me.ScrollHeight = Me.Height
      Me.Height = Me.Height * 0.5
      Me.ScrollBars = fmScrollBarsVertical
      
      
      'setup Topic Listbox
      With Sheets("2012 4th LOC SHOP")
        .Range(.Cells(1, 6), .Cells(1, .Cells(1, Columns.Count).End(xlToLeft).Column)).Name = "topics"
       End With
      cbx_Topic_Choice.List = Split(Join(Filter([if(topics <>"(required)",topics,"~")], "~", False), "|"), "|")
    End Sub
    Harry.

  4. #4
    Forum Contributor
    Join Date
    03-21-2004
    Location
    Norwich, CT USA
    MS-Off Ver
    Excel 2010
    Posts
    163

    Re: Create combobox .list excluding some columns

    John, that worked perfect. Also with your method I don't have to use the worksheet transpose function.Thanks
    Robert

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Create combobox .list excluding some columns

    Hi Robert

    You're welcome...glad I could help. Thanks for the Rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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