I see couple of problems
- You are using - xlDownto find the last cell. I would recommend seeing THIS link on how to find last row.
 
- You are getting the error - Runtime Error 9 Subscript out of rangebecause Excel cannot find the sheet that you are referring to. Please ensure that the sheet exists. If you can visually see the- Untitledsheet then I believe the sheet name has leading or trailing spaces.
 
- Once you solve that issue, the next error that you will get is - Runtime error 438: Object doesn't support this property or method. And that is because you are using- cellinstead of- cells. For example- .cell(i, 1)should be- .Cells(i, 1)and- .cell(i + 1, 1)should be- .Cells(i + 1, 1)
 
- Declare your objects else if - Sheets("Untitled")is not the active sheet then- Rows(i).Deletewill delete from the wrong sheet ;)
 
- Avoid deleting the rows in a loop. It will only make your code slower. See how I have used - delRangein the code below.
 
Fix these things and you will be good to go
Note:
Option Explicit
Sub em()
    Dim delRange As Range
    Dim ws As Worksheet
    Dim i As Long, LRow As Long
    Set ws = ThisWorkbook.Sheets("Untitled")
    With ws
        LRow = .Range("A" & .Rows.Count).End(xlUp).Row
        For i = LRow To 2 Step -1 '~~> Even 2 To LRow will work :)
            If .Cells(i, 1) = .Cells(i + 1, 1) Then
                If delRange Is Nothing Then
                    Set delRange = .Rows(i)
                Else
                    Set delRange = Union(delRange, .Rows(i))
                End If
            End If
        Next i
        If Not delRange Is Nothing Then delRange.Delete
    End With
End Sub