Reputation: 97
I created an Excel macro intended to merge the content of all selected multiple rows one col into last row, as code below:
Sub asdf()
Dim rCell As Range
Dim rRng As Range
Dim rslt As String
Dim lastCell As Range
Dim i As Integer
Set rRng = Range(Selection.Address)
For Each rCell In rRng.Cells
Debug.Print rCell.Address, rCell.Value
rslt = rslt & " " & rCell.Value
rslt = Trim(rslt)
rCell.Value = rslt
Next rCell
End Sub
The question is, how to delete all those multiple (whole) rows except the last row?
Upvotes: 1
Views: 54
Reputation: 2816
You can try this
Sub asdf()
Dim delCell as Range
Dim rCell As Range
Dim rRng As Range
Dim rslt As String
Dim lastCell As Range
Dim i As Integer
Set rRng = Range(Selection.Address)
For Each rCell In rRng.Cells
Debug.Print rCell.Address, rCell.Value
rslt = rslt & " " & rCell.Value
rslt = Trim(rslt)
If Not rCell.Row = rRng.Row + rRng.Rows.Count - 1 Then
If delCell is Nothing then
set delCell = rCell
Else
set delcell = union(delCell, rCell)
End If
End If
rCell.Value = rslt
Next rCell
delCell.EntireRow.Delete
End Sub
Upvotes: 1