Forum

Need Macro for dele...
 
Notifications
Clear all

Need Macro for deleting entire row, when value in all 4 cells of row less than qty 1

7 Posts
4 Users
0 Reactions
110 Views
(@daneo42)
Posts: 3
Active Member
Topic starter
 

I've never done a VBA or macro before. This would help me alot if somebody can help with a formula

If cells in same row, columns C,D,E, and F all <1 ,  delete entire row 

in my example photo, row 2 and 4 would be deleted,  row 3 and 5 would not

 
Posted : 23/01/2019 11:33 am
Anders Sehlstedt
(@sehlsan)
Posts: 971
Prominent Member
 

Hello,

I noticed that Jon Acampora just uploaded such example.

https://www.excelcampus.com/error-creating-relationship-in-vba-userform-code/delete-rows-cell-values/

 
Posted : 23/01/2019 6:44 pm
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Dane

Just in case the article by Jon Acampora is too overwhelming (since you are new to VBA/macros) you can give this a try

Sub DelRows()
Dim LastRow As Long
Dim i As Long

LastRow = Cells(Rows.Count, "A").End(xlUp).Row

Application.ScreenUpdating = False
For i = LastRow To 1 Step -1
'Count how many values are less than 1
If Application.CountIf(Range("C" & i & ":F" & i), "<1") = 4 Then

'Delete entire row if count is equal to 4
Rows(i).Delete Shift:=xlUp
End If
Next
Application.ScreenUpdating = True
End Sub

Hope this helps.

Sunny

 
Posted : 23/01/2019 9:12 pm
(@daneo42)
Posts: 3
Active Member
Topic starter
 

That worked great. Thank  you so much Sunny!

 
Posted : 24/01/2019 10:49 am
(@sunnykow)
Posts: 1417
Noble Member
 

No problem.

 
Posted : 24/01/2019 9:12 pm
(@debaser)
Posts: 837
Member Moderator
 

Just for info, you could also use an autofilter for that:

 

Sub DelRowsLessThanOne()
Application.ScreenUpdating = False
With Range("A1").CurrentRegion
.AutoFilter field:=3, Criteria1:="<1"
.AutoFilter field:=4, Criteria1:="<1"
.AutoFilter field:=5, Criteria1:="<1"
.AutoFilter field:=6, Criteria1:="<1"
If .Columns(1).SpecialCells(xlCellTypeVisible).Count > 1 Then
.Offset(1).Columns(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End If
.AutoFilter
End With
End Sub

 
Posted : 25/01/2019 6:03 am
(@daneo42)
Posts: 3
Active Member
Topic starter
 

that is AWESOME!!  you all are the best!

these are going to save me hours of my life 

 

thank you so much

 
Posted : 26/01/2019 2:32 pm
Share: