Macro to combine data in a column

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If I select a block of contiguous cells in the same column, is it possible to
create a macro that will combine all the data, in the order of top selected
cell to the bottom selected cell and place it in proper order into a single
cell (the top cell of the selected block)--I don't want to merge the cells, I
just want all the data from a block of selected cells to be placed into one
cell.

Thanks.
 
Do you want to clear all of the other cells?

Sub test()
Dim c As Range
Dim s As String

For Each c In Selection
s = s & IIf(s = "", "", Chr(10)) & c.Value
Next c

Selection.Cells.Value = ""
Selection.Cells(1).Value = s
End Sub


Tim.
 
This should get u started

Sub combine()

C = Empty
Range("B4:b8").Select
D = ActiveCell.Value
Dim A As String
A = Selection.Address
Dim C As String
Do Until ActiveCell = ""
C = C & D
D = ActiveCell.Offset(1, 0).Value
ActiveCell.Offset(1, 0).Activate
Loop
Range(A).Select
ActiveCell = C

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top