Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

concatenate / merge multiple text cells 1

Status
Not open for further replies.

paulrbarnard

Technical User
Jul 9, 2001
2
CA
I have a large spreadsheet with comments attached to the data in the row. Unfortunatly some previous administrators of the spreadsheet have added additional rows/cols to add extra comments rather than keeping them all in the existing cell. This is a disaster when it comes to sorting the data

Example

1 data1 "comment1, comment2, comment3" - what should be there
2 data2 "comment1" "comment2" "comment3" - what I've got

I have been trying to write a macro that lets me select the required cells then concatenates the text into the active cell. This has so far got me beat. Can anyone help out?

Thanks
Paul
 
try this!!

Sub MyMerge()
Dim MyRange As Range
Dim MyStr As String
Dim MyLen As Integer
Set MyRange = Selection
For Each MyCell In MyRange
MyStr = MyStr & ", " & MyCell.Value
MyLen = Len(MyStr)
MyStr = Mid(MyStr, 2, MyLen)
Next
Application.DisplayAlerts = False
Selection.Merge
Selection.Value = MyStr
Application.DisplayAlerts = True
End Sub
Jamie Gillespie
j-gillespie@s-cheshire.ac.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top