VBA code to delete rows IF cell contains certain text AND other cell = 0

cash2021

New Member
Joined
Dec 5, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I've tried this about a million different ways & cannot seem to get it to work. I'm an amateur when it comes to VBA. My goal is to delete entire rows if value in column G is "0" & column L is "FALSE" to regularly clean up this spreadsheet & keep it from becoming overwhelming. For context - columns in yellow are formulas that calculate based on cell values in columns A:H, & since the ultimate goal is to delete rows with dates before yesterday AND column G = 0, I've also tried using the date/now functions with no luck (hence moving on to the true/false column, since I already had it sitting there to filter a pivot table). I've pasted the code I'm attempting to use below along with a screenshot of what the data looks like. Little help would be awesome!

1607225400876.png


VBA Code:
Sub DeleteRows()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
 Dim LR As Long, i As Long
LR = Range("G" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
   If (Range("G" & i) = "0" And Range("L" & i) = "FALSE") Then Rows(i).Delete
Next i
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
So try this looks in column A for Date less the yesterday and "0" in column
VBA Code:
Sub Delete_Rows()
'Modified 12/6/2020  5:03:49 AM  EST
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row

For i = Lastrow To 2 Step -1
    If Cells(i, 1).Value < Date - 1 And Cells(i, "G").Value = "0" Then Rows(i).Delete
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
So try this looks in column A for Date less the yesterday and "0" in column
VBA Code:
Sub Delete_Rows()
'Modified 12/6/2020  5:03:49 AM  EST
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row

For i = Lastrow To 2 Step -1
    If Cells(i, 1).Value < Date - 1 And Cells(i, "G").Value = "0" Then Rows(i).Delete
Next
Application.ScreenUpdating = True
End Sub
INCREDIBLE! This worked beautifully - looks like the issue was referencing the range rather than the cells themselves? Can't thank you enough! :)
 
Upvote 0
INCREDIBLE! This worked beautifully - looks like the issue was referencing the range rather than the cells themselves? Can't thank you enough! :)
Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,746
Members
448,989
Latest member
mariah3

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