Ah finally I have finish coding for you...please try it....
Sub CleanIncompleteRow()
ActiveSheet.Name = "WorkSh"
lstCol = Range(Cells(1, Columns.Count).Address).End(xlToLeft).Column
lstRow = Range("A" & Rows.Count).End(xlUp).Row
For Each cell In Range("A1:" & Cells(1, lstCol).Address)
If cell.Value = "" Then
cell.Value = "TempFiled" & cell.Column()
End If
Next
'Create Index to control row number for original sequence
Cells(1, lstCol + 1).Value = "Control Index"
For i = 2 To Sheets(1).Range("A" & Rows.Count).End(xlUp).Row
If Cells(i - 1, lstCol + 1).Value = "Control Index" Then
Cells(i, lstCol + 1).Value = 1
Else
Cells(i, lstCol + 1).Value = Cells(i - 1, lstCol + 1).Value + 1
End If
Next i
'Create temp field for duplication check
Sheets(1).Range("A:C").EntireColumn.Insert
Range("A1").Value = "CheckDup"
Range("B1").Value = "CheckIndex2"
Range("C1").Value = "CheckIndex1"
prdCodeCol = Application.WorksheetFunction.Match("Product", Range("1:1"), 0)
ctryCol = Application.WorksheetFunction.Match("Country", Range("1:1"), 0)
postPrdCol = Application.WorksheetFunction.Match("Posting period", Range("1:1"), 0)
ctrlIndexCol = Application.WorksheetFunction.Match("Control Index", Range("1:1"), 0)
For Each prdCell In Range(Cells(2, postPrdCol).Address & ":" & Cells(lstRow, postPrdCol).Address)
prdCell.Value = prdCell.Value * 1
Next
'Create Check Index 1
For Each index1Cell In Range("C2:C" & lstRow)
index1Cell.Value = Cells(index1Cell.Row, prdCodeCol).Value & Cells(index1Cell.Row, ctryCol).Value
Next
'Sort to get the lastest Posting period, make sure the last post will be kept
Worksheets("WorkSh").Range("A1").Sort _
key1:=Worksheets("WorkSh").Columns("C"), order1:=xlDescending, _
key2:=Worksheets("WorkSh").Columns(postPrdCol), order2:=xlDescending, _
Header:=xlGuess
'Create Check Index 2
For Each index2Cell In Range("B2:B" & lstRow)
If index2Cell.Offset(0, 1).Value = index2Cell.Offset(-1, 1).Value Then
index2Cell.Value = index2Cell.Offset(-1, 0).Value
Else
index2Cell.Value = Range(Cells(index2Cell.Row, postPrdCol).Address).Value
End If
Next
'Create Check Duplication
For Each ChkDupCell In Range("A2:A" & lstRow)
If ChkDupCell.Offset(-1, 0).Value = "CheckDup" Then
ChkDupCell.Value = "Keep"
ElseIf ChkDupCell.Offset(0, 2).Value = ChkDupCell.Offset(-1, 2) Then
If Range(Cells(ChkDupCell.Row, prdCodeCol).Address).Value = ChkDupCell.Offset(0, 1).Value Then
ChkDupCell.Value = "Keep"
End If
Else
ChkDupCell.Value = "Keep"
End If
Next
'Delete all those duplicate
Range("A2:A" & lstRow).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
'Sort to get the the original sequence
Worksheets("WorkSh").Range("A1").Sort _
key1:=Worksheets("WorkSh").Columns(ctrlIndexCol), order1:=xlAscending, _
Header:=xlGuess
'Clear worksheet back to standard format
Columns(ctrlIndexCol).Delete
Range("A:C").Delete
MsgBox ("Done")
Range("A2").Select
End Sub
----------------------------------------- end of Code ----------------------------------------
Pichart Y.