Consulting

Results 1 to 5 of 5

Thread: Help with code

  1. #1

    Help with code

    Good afternoon,

    The code I'm using merges Columns into the first column selected, however they are all merged with a space for each column merged, can someone edit the code so it will do the same but without spaces, thanks

        Dim a, b
        Dim i As Long
      
        With Intersect(ActiveSheet.UsedRange, Selection)
            a = .Value
            ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
            For i = 1 To UBound(a, 1)
            b(i, 1) = Application.Trim(Join(Application.Index(a, i, 0)))
            Next i
            .Value = b
            .EntireColumn.AutoFit
        End With

  2. #2
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    try this:
    b(i, 1) = Join(Application.Index(a, i, 0), "")

  3. #3
    VBAX Tutor PAB's Avatar
    Joined
    Nov 2011
    Location
    London (UK)
    Posts
    243
    Location
    Give this a go...

    Sub mrg()
        Dim a, b
        Dim i As Long
         
        With Intersect(ActiveSheet.UsedRange, Selection)
            a = .Value
            ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
            For i = 1 To UBound(a, 1)
                b(i, 1) = Join(Application.Index(a, i, 0), "")
            Next i
            .Value = b
            .EntireColumn.AutoFit
        End With
    End Sub
    I hope this helps!
    -----------------------------------------∏-

    12:45, restate my assumptions.
    Mathematics is the language of nature.
    Everything around us can be represented and understood through numbers.
    If you graph the numbers of any system, patterns emerge. Therefore, there are patterns everywhere in nature.

    -----------------------------------------∏-

  4. #4
    Thanks JKwan and PAB, they both work perfectly.

  5. #5
    VBAX Tutor PAB's Avatar
    Joined
    Nov 2011
    Location
    London (UK)
    Posts
    243
    Location
    Quote Originally Posted by decadence View Post
    Thanks JKwan and PAB, they both work perfectly.
    You're welcome, although JKwan beat me to it.
    Thanks for the feedback.
    -----------------------------------------∏-

    12:45, restate my assumptions.
    Mathematics is the language of nature.
    Everything around us can be represented and understood through numbers.
    If you graph the numbers of any system, patterns emerge. Therefore, there are patterns everywhere in nature.

    -----------------------------------------∏-

Posting Permissions

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