PC Review


Reply
Thread Tools Rate Thread

Delete 0 - Column D and Column F

 
 
EJ
Guest
Posts: n/a
 
      15th May 2009
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

 
Reply With Quote
 
 
 
 
FSt1
Guest
Posts: n/a
 
      15th May 2009
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
>

 
Reply With Quote
 
EJ
Guest
Posts: n/a
 
      15th May 2009
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
> >

 
Reply With Quote
 
FSt1
Guest
Posts: n/a
 
      15th May 2009
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
> > >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy column header to next column, delete & delete every nth colum genehunter Microsoft Excel New Users 1 2nd Jun 2009 03:57 PM
Find Column heading and then Delete entire column Kobayashi Microsoft Excel Programming 4 17th Oct 2005 09:09 PM
Delete All Rows That Column A value is not in Column A of Sheet2 paxdak@yahoo.com Microsoft Excel Programming 2 3rd Sep 2004 09:13 PM
Re: Delete data only (all) from one column without deleting column itself John Vinson Microsoft Access 0 18th Sep 2003 05:51 PM
Re: Delete data only (all) from one column without deleting column itself Mike Painter Microsoft Access 1 18th Sep 2003 05:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:51 PM.