Delete rows macro help

Jazzer

Board Regular
Joined
Jun 14, 2011
Messages
71
Hi Guys<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I use a macro to delete rows when a cell contains specific data.<o:p></o:p>
on another sheet I would like to use some similar but with slightly more complicated variables<o:p></o:p>
<o:p> </o:p>
Basically I want to delete any row which does not contain 710 in column K unless that row contains 1788 in column N in which case it can stay!<o:p></o:p>
<o:p> </o:p>
Can anybody help please?<o:p></o:p>
<o:p> </o:p>
Thanks<o:p></o:p>
James<o:p></o:p>
<o:p> </o:p>
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Put this in your worksheet moduel
Code:
Sub kpark91July132011()
    Application.ScreenUpdating = False
    Dim i&, LR&
    LR& = Range("a" & Rows.count).End(xlUp).Row
    For i =  LR To 1 Step - 1
        If Range("N" & i).Value <> 1788 Then
            If Range("K" & i).Value <> 710 Then
                Range("A" & i).EntireRow.Delete
            End If
        End If
    Next i
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Code:
Sub DeleteRows()
Dim r As Long
Dim lrow As Long
Application.ScreenUpdating = False
lrow = Range("K" & Rows.Count).End(xlUp).Row
For r = lrow To 2 Step -1

If Cells(r, 11).Value <> 710 And Cells(r, 14).Value <> 1788 Then
    Rows(r).Delete
End If

Next r
Application.ScreenUpdating = True
End Sub
Try this
 
Last edited:
Upvote 0
Code:
Sub DeleteRows()
Dim r As Long
Dim lrow As Long
Application.ScreenUpdating = False
lrow = Range("K" & Rows.Count).End(xlUp).Row
For r = lrow To 2 Step -1
 
If Cells(r, 11).Value <> 710 And Cells(r, 14).Value <> 1788 Then
    Rows(r).Delete
End If
 
Next r
Application.ScreenUpdating = True
End Sub
Try this

I should mention the data starts in Row 9 - is there specific way that I should include the range?<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
 
Upvote 0
Just change
Rich (BB code):
For r = lrow To 2 Step - 1

to

Rich (BB code):
For r = lrow To 9 Step -1
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,799
Members
452,943
Latest member
Newbie4296

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