PDA

View Full Version : Help with code



decadence
04-11-2016, 06:40 AM
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

JKwan
04-11-2016, 07:38 AM
try this:

b(i, 1) = Join(Application.Index(a, i, 0), "")

PAB
04-11-2016, 07:45 AM
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!

decadence
04-11-2016, 07:50 AM
Thanks JKwan and PAB, they both work perfectly.

PAB
04-11-2016, 07:53 AM
Thanks JKwan and PAB, they both work perfectly.

You're welcome, although JKwan beat me to it.
Thanks for the feedback.