VBA/Macro help needed with row delete based on Column A value

robospike

New Member
Joined
Mar 22, 2016
Messages
22
Hi,

I have a for loop (provided as an answer to a seperate question), this loop moves through every row with a value in column A.

I now wish to reuse this code in a new way, to remove any rows that contain 110 or 111 within column A. I have drafted the below code but am not really sure how to acheve this, if anyone has any ideas, I would be greatful.


Code:
Sub DeleteRowTest()

Dim LR  As Long
Dim i   As Long

LR = Range("A" & Rows.Count).End(xlUp).Row()

For i = 1 To LR
   If Range("i1").Value = "110" Then
      MsgBox ("YES")
      'Rows("??").Select
      'Selection.EntireRow.Delete
    ElseIf Range("i1").Value = "111" Then
      MsgBox ("YES")
      'Rows("??").Select
      'Selection.EntireRow.Delete
   Else
      'Return
   End If
Next i

End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Based on another question asked almost at the same time as mine, I have found a solution:

Code:
Sub DeleteRowTest2()

With Intersect(ActiveSheet.UsedRange, Range("A:A"))
    .AutoFilter Field:=1, Criteria1:="101"
    On Error Resume Next
    .Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    On Error GoTo 0
    .AutoFilter
End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top