ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete 0 - Column D and Column F (https://www.excelbanter.com/excel-programming/428571-delete-0-column-d-column-f.html)

EJ

Delete 0 - Column D and Column F
 
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


FSt1

Delete 0 - Column D and Column F
 
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
"EJ" wrote:

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


EJ

Delete 0 - Column D and Column F
 
This works fantastically. Thank you.

"FSt1" wrote:

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
"EJ" wrote:

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


FSt1

Delete 0 - Column D and Column F
 
glad to help. thanks for the feedback.
regards
FSt1

"EJ" wrote:

This works fantastically. Thank you.

"FSt1" wrote:

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
"EJ" wrote:

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



All times are GMT +1. The time now is 11:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com