Delete Rows Based on Values in Multipul Column

mayuko

New Member
Joined
Jul 8, 2011
Messages
9
I need to make a macro to do this...:(

"If there are values in column G, but nothing in column L and N, then delete rows"

It would be appreciated if anyone could help me with this.

Thank you:)
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Code:
Sub Del_Rows()
    Dim i As Long
    Application.ScreenUpdating = False
    For i = Range("G" & Rows.Count).End(xlUp).Row To 1 Step -1
        If Range("G" & i) <> "" And Range("L" & i) = "" And Range("N" & i) = "" Then Rows(i).Delete
    Next i
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Code:
Sub blah()
With ActiveSheet
    toprow = .UsedRange.Row
    lastrow = toprow + .UsedRange.Rows.Count - 1
    For i = lastrow To toprow Step -1
        If (Not IsEmpty(.Cells(i, "G"))) And IsEmpty(.Cells(i, "L")) And IsEmpty(.Cells(i, "N")) Then .Rows(i).Delete
    Next i
End With
End Sub
 
Upvote 0
Thank you very much, AlphaFrog and p45cal :)

I am so sorry. Either of them worked. Both of them left rows that have empty cells in L and N...
 
Upvote 0
Did you want to delete rows if L OR N was blank?

If yes, then change this...
Code:
If Range("G" & i) <> "" And Range("L" & i) = "" And Range("N" & i) = "" Then Rows(i).Delete

To this...
Code:
If Range("G" & i) <> "" And (Range("L" & i) = "" Or Range("N" & i) = "") Then Rows(i).Delete
 
Upvote 0
Thanks AlphaFrog. I am sure it is And... I ran it after I changed it to Or, then it deleted ones I wanted to leave :(
 
Upvote 0
Maybe try this...

Code:
If Range("G" & i) <> "" And (Trim(Range("L" & i)) = "" And Trim(Range("N" & i)) = "") Then Rows(i).Delete

If the so-called empty cells in L and N contained a space, they may "look" empty but are not really empty. The Trim function would effectively erase the space in those cases.
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,558
Members
452,928
Latest member
101blockchains

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