Results 1 to 10 of 24

Thread: Flexible Concatenation Function

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    14
    Quote Originally Posted by javanchi View Post
    Rick, data can go into the adjacent columns to the right of the data fields. All is text, but that field shows an error because the cell starts with an "=".
    I'm glad I asked about that #NAME? error as those lines of code required special handling. Give this macro a try...
    Code:
    Sub ConcatDashedRanges()
      Dim NextRow As Long, TempText As String, EmptyCells As Range, EqualSignCells As Range, Ar As Range
      On Error Resume Next
      Set EqualSignCells = Columns("A").SpecialCells(xlFormulas)
      For Each Ar In EqualSignCells
        Ar.Value = "'" & Ar.Formula
      Next
      Set EmptyCells = Columns("A").SpecialCells(xlConstants)
      For Each Ar In EmptyCells.Areas
        NextRow = NextRow + 1
        TempText = Application.Trim(Join(Application.Transpose( _
                   Ar.Offset(1).Resize(Ar.Count - 1).Value), ";"))
        If Left(TempText, 1) = "=" Then TempText = "'" & TempText
        Cells(NextRow, "B").Value = TempText
      Next
    End Sub
    I highlighted in red the location where the delimiter is specified in case you want to change it in the future.
    Last edited by Rick Rothstein; 02-14-2013 at 05:54 AM.

  2. #2
    Junior Member
    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0
    Quote Originally Posted by Rick Rothstein View Post
    I'm glad I asked about that #NAME? error as those lines of code required special handling. Give this macro a try...
    I highlighted in red the location where the delimiter is specified in case you want to change it in the future.


    Rick,

    The macro worked very nicely. My team is very impressed!!

    Can we nuance it to align the concatented line directly to the right of its starting point rather than at the top of the column?

    JOHN

  3. #3
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    14
    Quote Originally Posted by javanchi View Post
    Rick,

    Can we nuance it to align the concatented line directly to the right of its starting point rather than at the top of the column?
    Is this what you are looking for?
    Code:
    Sub ConcatDashedRanges()
      Dim TempText As String, EmptyCells As Range, EqualSignCells As Range, Ar As Range
      On Error Resume Next
      Set EqualSignCells = Columns("A").SpecialCells(xlFormulas)
      For Each Ar In EqualSignCells
        Ar.Value = "'" & Ar.Formula
      Next
      Set EmptyCells = Columns("A").SpecialCells(xlConstants)
      For Each Ar In EmptyCells.Areas
        TempText = Application.Trim(Join(Application.Transpose( _
                   Ar.Offset(1).Resize(Ar.Count - 1).Value), ";"))
        If Left(TempText, 1) = "=" Then TempText = "'" & TempText
        Ar(1).Offset(1, 1).Value = TempText
      Next
    End Sub
    If you want the output aligned with the dashes instead of the first text line, change the red highlighted 1 (one) to a 0 (zero).
    Last edited by Rick Rothstein; 02-15-2013 at 09:46 PM.

Similar Threads

  1. UDF (user defined function) replacement for Excel's DATEDIF function
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 21
    Last Post: 03-07-2015, 09:47 PM
  2. FORMATTED Flexible Concatenation Function
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 1
    Last Post: 10-14-2012, 03:48 PM

Tags for this Thread

Posting Permissions

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