Hi

I assume your sheet has data in Col A through Col D (at least one cell in each col) , otherwise my code won't work.

Code:
Sub kTest()
        
    Dim b   As String, d As String
    
    Const TrailingChar = "x"    'adjust the char
    Const BlankChar = "####"
    Const DeleChar = "||||"
    
    Application.ScreenUpdating = False
    
    With Intersect(ActiveSheet.UsedRange, Range("a:d"))
        b = .Columns(2).Address
        d = .Columns(4).Address
        On Error Resume Next
        .Columns(2).SpecialCells(4) = BlankChar
        .Columns(2) = Evaluate("if(" & d & "=0,if(right(" & b & ",len(""" & TrailingChar & """))=""" & TrailingChar & """,""" & DeleChar & """," & b & ")," & b & ")")
        .Columns(2).Replace DeleChar, vbNullString, 1
        .Columns(2).SpecialCells(4).EntireRow.Delete
        .Columns(2).Replace BlankChar, vbNullString, 1
    End With
    
    Application.ScreenUpdating = True
    
End Sub