RWayneH
asked on
Rewriting a Delete Rows Sub
How would I adj this code to delete everything that is in column H, that is not an "M"? However I need to do this on the activate sheet tab.
Sub Delete_Data()
Set stInp = Sheets("Sheet2")
oriInputCnt = stInp.Cells(stInp.Rows.Count, "H").End(xlUp).Row
If oriInputCnt > 5 Then stInp.Rows("6:" & oriInputCnt).EntireRow.Delete Shift:=xlUp
End Sub
For no points you don't need the v variable.
Sub Deletes()
Dim Ws As Worksheet
Dim LR As Long, i As Long
Set Ws = Worksheets("Sheet2")
LR = Ws.Range("H" & Rows.Count).End(xlUp).Row
For i = LR To 6 Step -1
With Ws.Cells(i, "H")
If .Value <> "M" Then
.EntireRow.Delete
End If
End With
Next i
End Sub
ASKER
Well the Sheet name is really not Sheet2, it chg's need it to be whatever the active sheet is.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Change
Set Ws = Worksheets("Sheet2")
to
Set Ws = Activesheet
Set Ws = Worksheets("Sheet2")
to
Set Ws = Activesheet
ASKER
Thanks for the help.
You're Welcome RwayneH! Glad I was able to help :)
Please try below:
Open in new window