merge/ combine two row based on two separate value

I3atnumb3rs

New Member
Joined
Nov 2, 2018
Messages
34
Hello!

I want to be able to loop through a sheet and do the following:

if cell value in row 1, column A and B match the cells value of row 2, column A and B AND the cell value in row 1, column O = "REGULAR DELIVERY" and the cell value in row 2, column O = "RETURN", I want to combine/merge the two rows into 1 row, and merge the data found in columns C,K,and O. Hope this makes sense! My code isn't working :/



Sub DelRetConc()


Dim firstCell As Range
Dim lastCellRow As Integer


Dim rowNum As Long


For rowNum = 2 To Range("A" & Rows.Count).End(xlUp).Row


'Duplicates
If Application.WorksheetFunction.CountIf(Columns("B"), Cells(rowNum, "B")) > 1 Then

lastCellRow = Application.WorksheetFunction.CountIf(Columns(2), Cells(rowNum, 2))
LastRow = Application.WorksheetFunction.CountIf(Range(Cells(2, rowNum), Cells(rowNum, 2)), Cells(rowNum, 2))


If firstCell Is Nothing And Cells(rowNum, "O").Value = "REGULAR DELIVERY" And Cells(rowNum + 1, "O").Value = "RETURN" Then

Set firstCell = Cells(rowNum, 2)

ElseIf Cells(rowNum, "O").Value = "REGULAR DELIVERY" And Cells(rowNum + 1, "O").Value = "RETURN" Then

Cells(firstCell.Row, firstCell.Column + 1).Value = Cells(firstCell.Row, firstCell.Column + 1).Value & " / " & Cells(rowNum, "C")
' Cells(firstCell.Row, firstCell.Column + 1).Value = Cells(firstCell.Row, firstCell.Column + 1).Value & " " & Cells(rowNum, "K")
' Cells(firstCell.Row, firstCell.Column + 1).Value = Cells(firstCell.Row, firstCell.Column + 1).Value & " / " & Cells(rowNum, "O")


Cells(rowNum, 1).EntireRow.Delete
rowNum = rowNum - 1

End If

If lastCellRow = LastRow Then

Set firstCell = Nothing

End If

End If

Next rowNum


End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top