Consulting

Results 1 to 9 of 9

Thread: delete sign pilcrow in combobox

  1. #1

    delete sign pilcrow in combobox

    hi, tell, please, how to clean the sign pilcrow ( ¶ ) in combobox?
    Attached Files Attached Files

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Remove the Chr(10) in


    Private Sub UserForm_Initialize()
        With ComboBox2
            .AddItem "text" & Chr(10) & "number"
        End With
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    I need to keep a cell format = text 1
    number 1

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Remove the RowSource from the Combobox
    Private Sub UserForm_Initialize()
        Dim txtlist As Range, cel, x As String
        With Sheets(2)
        Set txtlist = Range(.Cells(1, 1), .Cells(10, 1))
        End With
        
        With ComboBox1
            .AddItem "text" & vbTab & "number"
            For Each cel In txtlist
                x = Replace(cel.Value, Chr(10), vbTab)
                .AddItem x
            Next
        End With
    End Sub
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    @mdmac

    Never use .additem or rowsource to populate a combobox/listbox; use .List instead.

    See http://www.snb-vba.eu/VBA_Fill_combobox_listbox_en.html

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Alternative
    Private Sub UserForm_Initialize()
        Dim txtlist As Range, cel, x As String
        Dim arr
        With Sheets(2)
             'arr needs an extra cell to hold the Combobox Header
            arr = Range(.Cells(1, 1), .Cells(10, 1)(2)).Value
        End With
        For a = UBound(arr) - 1 To 1 Step -1
            arr(a + 1, 1) = Replace(arr(a, 1), Chr(10), vbTab)
        Next
        arr(1, 1) = "Text" & vbTab & "Number"
        ComboBox1.List = arr
    End Sub
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    @snb
    Not that I didn't believe you, but I checked speed of both methods above;
    10 items over 5 runs
    AddItem = 2436, List = 12976
    1000 items over 5 runs
    AddItem = 5235, List = 17408
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    FWIW, for me List was ~10 times faster than AddItem for 1000 items. Interestingly, for both methods it took longer to populate a listbox than a combo box.

  9. #9
    thank you very much

Posting Permissions

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