Adding a condition to a macro

BarryL

Well-known Member
Joined
Jan 20, 2014
Messages
1,421
Hi All,

I have the below code that deletes everything that is equal to one in column D. I want to add in a condition where it deletes everything equal to one in column D as long as the corresponding row in column B is not blank.

Sub DeleteD1()
Dim LR As Long, i As Long
LR = Range("D" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
For i = LR To 1 Step -1
If Range("D" & i).Value = 1 Then Rows(i).Delete
Next i
Application.ScreenUpdating = True
End Sub

Thank you.

Barry
 

Some videos you may like

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Reggie74

Board Regular
Joined
Sep 26, 2014
Messages
51
Try this ... ;)

Code:
Sub DeleteD1()


    Dim LR As Long, i As Long
    
    LR = Range("D" & Rows.Count).End(xlUp).Row
    
    Application.ScreenUpdating = False
    
    For i = LR To 1 Step -1
        If Range("D" & i).Value = 1 [B]And Range("B" & i).Value <> "" [/B]Then Rows(i).Delete
    Next i
    Application.ScreenUpdating = True
    
End Sub

Hi All,

I have the below code that deletes everything that is equal to one in column D. I want to add in a condition where it deletes everything equal to one in column D as long as the corresponding row in column B is not blank.

Sub DeleteD1()
Dim LR As Long, i As Long
LR = Range("D" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
For i = LR To 1 Step -1
If Range("D" & i).Value = 1 Then Rows(i).Delete
Next i
Application.ScreenUpdating = True
End Sub

Thank you.

Barry
 

Watch MrExcel Video

Forum statistics

Threads
1,109,161
Messages
5,527,156
Members
409,750
Latest member
BorisYeltsin

This Week's Hot Topics

Top