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
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