I need to write a macro to clean up an Excel document. I have most of the functions working now but I am having trouble merging two rows of data together. I need to first merge two rows of data, then delete the second one. This block of code is from the function I am having trouble with, I am deleting the correct rows fine but I would like to first merge together the row I want to delete with the row above so no data is lost; does anyone know if there’s a quick command to merge whole rows together or do I have to do it cell by cell.
For RowCount = Selection.Rows.Count To 1 Step -1
' Delete rows that don't have text in col A
If Selection.Cells(RowCount, 1).Text <> "" And IsNumeric(Selection.Cells(RowCount, 1).Value) Then
'Is Number
ElseIf Selection.Cells(RowCount, 1).Text = "Heading" Then
'Its the Heading
Else
'Its not needed!
'*********************************************************
'CODE TO MERGE TWO ROWS SHOULD GO HERE********************
'(MERGE ROWCOUNT-1 WITH ROWCOUNT AND DELETE ROWCOUNT)*****
'*********************************************************
Selection.Rows(RowCount).EntireRow.Delete
End If
' Start next iteration of RowCount loop.
Next RowCount
I think you need to do it cell by cell.
Replace:
With: