Convert data into one WrapText cell

  • Thread starter Thread starter Stuart
  • Start date Start date
S

Stuart

User's data is as follows:

G Data......................... 4 no 5 20
more Data ...............
etc

where G through 20 is in a single row, and therefore
Data occupies 3 rows.

I believe this gives me a complete record where the Data
occupies more than one row:

Sub TestConvertToWrapText()
Dim Cell As Range, StartRw As Long
Dim EndRw As Long

For Each Cell In ActiveSheet.Range("B2:B33")
If Not IsEmpty(Cell) Then
StartRw = Cell.Row
If Not IsEmpty(Cell.Offset(1, 0)) Then
EndRw = Cell.End(xlDown).Row
End If
End If
Next
End Sub

Can anyone please show me how to take this record
and paste it such that it occupies a single row?

Regards.
 
Many thanks. Helped a lot.

Regards.

Dave Peterson said:
When I'm doing this kind of thing, I usually delete the row that I merged into
the one above.

Option Explicit
Sub TestConvertToWrapText()

Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim delRng As Range

With ActiveSheet
FirstRow = 2
LastRow = 33 '.Cells(.Rows.Count, "B").End(xlUp).Row

For iRow = LastRow To FirstRow + 1 Step -1
If IsEmpty(.Cells(iRow, "B")) Then
'do nothing
Else
If IsEmpty(.Cells(iRow - 1, "B")) Then
'do nothing
Else
.Cells(iRow - 1, "B").Value = .Cells(iRow - 1, "B").Value _
& vbLf & .Cells(iRow, "B").Value
If delRng Is Nothing Then
Set delRng = .Cells(iRow, "B")
Else
Set delRng = Union(delRng, .Cells(iRow, "B"))
End If
End If
End If
Next iRow

If delRng Is Nothing Then
'do nothing
Else
delRng.EntireRow.Delete
End If
End With

End Sub

And I concatenated the cells with alt-enters (vblf). You may not want this.
 
Back
Top