decadence
Well-known Member
- Joined
- Oct 9, 2015
- Messages
- 525
- Office Version
- 365
- 2016
- 2013
- 2010
- 2007
- Platform
- Windows
Hi, i am trying to merge cells together comma delimited, I am almost there but need help, Can someone help with this please.
This is what I end up with so far
[TABLE="class: grid, width: 250"]
<tbody>[TR]
[TD]a,b,c,d,[/TD]
[TD]b[/TD]
[TD]c[/TD]
[TD]d[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
But What I would like to do is this
From This
[TABLE="class: grid, width: 250"]
<tbody>[TR]
[TD]a[/TD]
[TD]b[/TD]
[TD]c[/TD]
[TD]d[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
To This
[TABLE="class: grid, width: 250"]
<tbody>[TR]
[TD]a,b,c,d[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Code:
Sub MergeCommaDel()
'
Dim objSelection, objCell As range, MyStr As String
Application.ScreenUpdating = False
On Error Resume Next
Set objSelection = Intersect(Selection, ActiveSheet.UsedRange)
For Each objCell In objSelection
MyStr = MyStr & VBA.Trim$(objCell) & ","
Next
With ActiveWindow
.Selection(1, 1).NumberFormat = "@"
.Selection(1, 1).Value = MyStr
End With
End Sub
This is what I end up with so far
[TABLE="class: grid, width: 250"]
<tbody>[TR]
[TD]a,b,c,d,[/TD]
[TD]b[/TD]
[TD]c[/TD]
[TD]d[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
But What I would like to do is this
From This
[TABLE="class: grid, width: 250"]
<tbody>[TR]
[TD]a[/TD]
[TD]b[/TD]
[TD]c[/TD]
[TD]d[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
To This
[TABLE="class: grid, width: 250"]
<tbody>[TR]
[TD]a,b,c,d[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]