Delete 0 - Column D and Column F

E

EJ

Is there a macro that will check each row in Column D and Column F for "0",
so that when both columns in the same row have "0" and only when both columns
in the same row have "0" the contents "0" in that row of Column D and F will
be deleted simultaneously? I know the code below will delete the contents
but only if its in row D.


Sub DeletezerowhenincolumnDandColumnF()
Dim myLastRow As Long
Dim r As Long
Dim c As Range
myLastRow = ActiveSheet.Cells(10000, 4).End(xlUp).Row
For r = myLastRow To 1 Step -1
Set c = ActiveSheet.Range("d" & r)
If c.Value = "0" Then
c.ClearContents
End If
Next r
End Sub
 
F

FSt1

hi
i modified your code. works in xl03
Sub DeletezerowhenincolumnDandColumnF()
Dim myLastRow As Long
Dim r As Long
Dim c As Range
myLastRow = ActiveSheet.Cells(10000, 4).End(xlUp).Row
For r = myLastRow To 1 Step -1
Set c = ActiveSheet.Range("d" & r)
If c.Value = 0 And c.Offset(0, 2) = 0 Then
c.ClearContents
c.Offset(0, 2).ClearContents
End If
Next r
End Sub

regards
FSt1
 
E

EJ

This works fantastically. Thank you.

FSt1 said:
hi
i modified your code. works in xl03
Sub DeletezerowhenincolumnDandColumnF()
Dim myLastRow As Long
Dim r As Long
Dim c As Range
myLastRow = ActiveSheet.Cells(10000, 4).End(xlUp).Row
For r = myLastRow To 1 Step -1
Set c = ActiveSheet.Range("d" & r)
If c.Value = 0 And c.Offset(0, 2) = 0 Then
c.ClearContents
c.Offset(0, 2).ClearContents
End If
Next r
End Sub

regards
FSt1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top