Required Op: loc_id name HYD001 hyd HYD001 hyd HYD001 hyd HYD001 hyd HYD001 ban HYD001 ban HYD001 ban HYD001 pune HYD001 xyz HYD001 ban HYD002 hyd HYD002 hyd HYD002 hyd HYD002 hyd HYD002 ban HYD002 ban HYD002 ban HYD002 pune HYD002 xyz HYD002 ban
Sub Cleaning3() Dim wsh As Worksheet Dim i As Integer ', idcounter As Integer 'context Set wsh = ThisWorkbook.Worksheets(1) ' 'idcounter = 1 'starting row i = 2 'till cell in col. A is not empty Do While wsh.Range("A" & i) <> "" 'if zero - get value from below cell If wsh.Range("A" & i) = 0 Then wsh.Range("A" & i) = wsh.Range("A" & i).Offset(RowOffset:=1) End If 'if cell contains non-numeric value and it's not a "id" - get value from above cell If LCase(wsh.Range("A" & i)) <> "loc_id" And Not wsh.Range("A" & i) Like UCase(wsh.Range("B2")) & "*" Then wsh.Range("A" & i) = wsh.Range("A" & i).Offset(RowOffset:=-1) End If 'if "id" - remove entire row If LCase(wsh.Range("A" & i)) = "loc_id" Then wsh.Range("A" & i).EntireRow.Delete xlShiftUp i = i - 1 End If i = i + 1 Loop End Sub
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)