Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a macro that does the following:

  • Checks to see if consecutive rows have the same data (Columns F and G)

I need this macro to also somehow do the following:

  • If the data in Columns F and G are identical to the next row
  • Combine the data in Columns A,B,C,D,I, and J for both rows to the END of the first row. As if you had hit ALT + ENTER and entered the data

Any ideas?

Sub test()
 'define variables
  Dim RowNum as long, LastRow As long

 'turn off screen updating
  Application.ScreenUpdating = False

 'start below titles and make full selection of data
  RowNum = 2
  LastRow = Cells.SpecialCells(xlCellTypeLastCell).Row
  Range("A2", Cells(LastRow, 10)).Select

'For loop for all rows in selection with cells
 For Each Row In Selection
 With Cells

 'if first name matches
   If Cells(RowNum, 5) = Cells(RowNum + 1, 5) Then
    'and if last name matches
     If Cells(RowNum, 6) = Cells(RowNum + 1, 6) Then
        *******This is the part I cannot figure out!*******
        Rows(RowNum + 1).EntireRow.Delete
     End If
   End If
 End With

 'increase rownum for next test
  RowNum = RowNum + 1
  Next Row

 'turn on screen updating
  Application.ScreenUpdating = True

End Sub
share|improve this question

For appending the content of the cell Alt+Enter style use following code:

Cells(RowNum, 1).Value = Cells(RowNum, 1).Value & Chr(10) & Cells(RowNum + 1, 1).Value

That will work for cells in A column.

share|improve this answer
So I would need to use this argument separately for each column? – David Sep 19 '13 at 18:32
Yes. If some columns are adjacent, you can cycle through them with for, of course – Vladimir Tsuverkalov Sep 20 '13 at 12:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.