+ Reply to Thread
Results 1 to 3 of 3

Merge multiple cells in a column to strings no more than 100 characters long

Hybrid View

  1. #1
    Registered User
    Join Date
    12-06-2012
    Location
    Indiana
    MS-Off Ver
    Excel 2010
    Posts
    4

    Merge multiple cells in a column to strings no more than 100 characters long

    I have a list of text references in column C that I need to combine in to comma seperated strings that are no more than 100 characters each (including spaces and a auto-incremented prefix) in column I.

    The incremented prefix needs to start at 10 and increment by 10 for each new line as well as include the text "REM" to generate a quick basic type remark statement.

    The attached example shows what the final result needs to be but I have no clue where to begin with macro code for something like this. Please help!
    Attached Files Attached Files

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Merge multiple cells in a column to strings no more than 100 characters long

    This might work

    Option Explicit
    Sub abc()
     Dim a, b
     Dim i As Long, n As Long
     Dim increment As Long
     a = Range("c1", Cells(Rows.Count, "c").End(xlUp))
     
     ReDim b(0)
     increment = 10
     b(0) = increment & Space(1) & "REM" & Space(1)
     For i = 1 To UBound(a)
        If Len(b(UBound(b))) + Len(a(i, 1)) <= 100 Then
            b(UBound(b)) = b(UBound(b)) & a(i, 1) & ","
        Else
            b(UBound(b)) = Left$(b(UBound(b)), Len(b(UBound(b))) - 1)
            increment = increment + 10
            ReDim Preserve b(UBound(b) + 1)
            b(UBound(b)) = increment & Space(1) & "REM" & Space(1) & a(i, 1) & ","
        End If
     Next
     b(UBound(b)) = Left$(b(UBound(b)), Len(b(UBound(b))) - 1)
     Cells(1, "i").Resize(UBound(b) + 1) = Application.Transpose(b)
    End Sub
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Registered User
    Join Date
    12-06-2012
    Location
    Indiana
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Merge multiple cells in a column to strings no more than 100 characters long

    Worked like a dream! Thanks a million!

+ 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