+ Reply to Thread
Results 1 to 4 of 4

Display a 5 column range in a textbox or scrollable label

Hybrid View

Kingali Display a 5 column range in a... 05-16-2013, 06:27 AM
Kingali Re: Display a 5 column range... 05-16-2013, 07:19 PM
Norie Re: Display a 5 column range... 05-16-2013, 07:27 PM
Kingali Re: Display a 5 column range... 05-17-2013, 02:05 AM
  1. #1
    Registered User
    Join Date
    04-11-2013
    Location
    London, UK
    MS-Off Ver
    Excel 2010
    Posts
    12

    Question Display a 5 column range in a textbox or scrollable label

    Hi to all Gurus,

    I have a 5 column range that i want to display in a userform.
    As the range will grow in length I will need a scrollable textbox or label (don't think this can have scrollbars though??)
    I can get the range into a textbox, using a user function found on another website (sorry), but I need the data to wrap to the 5 columns, that is a new line after 5 values. I can't get my head around this part.

    Thanks in advance for the help.
    Kingali

  2. #2
    Registered User
    Join Date
    04-11-2013
    Location
    London, UK
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Display a 5 column range in a textbox or scrollable label

    Hi everyone,
    Solved it through trial and error and help. Code posted to help others.

    Public Function Join2(seperator As String, rng As Variant) As String
    'http://stackoverflow.com/questions/13121413/how-to-display-selected-range-of-cells-in-textbox1-using-vba-code
    
    Dim joinedString As String
    Dim cell As Variant
    Dim v As Integer
    
        v = 0
        For Each cell In rng
            v = v + 1
                joinedString = joinedString & cell & seperator
            If v = 5 Then
                joinedString = joinedString & vbCrLf
                v = 0
            End If
        Next cell
        joinedString = Left(joinedString, Len(joinedString) - Len(seperator))
        Join2 = joinedString
    End Function
    Kingali

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Display a 5 column range in a textbox or scrollable label

    Kingali

    Why not use a listbox?

    
    With Listbox1
         .ColumnCount = rng.Columns.Count
         .List = rng.value
    End With
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    04-11-2013
    Location
    London, UK
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Display a 5 column range in a textbox or scrollable label

    Hi Norie,
    Thanks for your reply.
    I have never used a listbox so didn't know its capabilities.
    Your solution automatically puts the values into their respective columns saving me extra coding.
    Ab Fab. That teaches me to look elsewhere. Stick with the forum you know and like. - Excelforum.com

    Thanks again
    Kingali

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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