PC Review


Reply
Thread Tools Rate Thread

Deleting entire row

 
 
daisy2008
Guest
Posts: n/a
 
      8th Dec 2008
I need an entire row deleted if column 2 on worksheet 3; date is one year
later but is less then todays date. I need this to run when my workbook is
opened.

Ex
B4 January 2, 2008
B5 November 4, 2007
B6 December 26, 2007
B7 December 5, 2007


Row 5 and row 7 are deleted when I open the workbook.


 
Reply With Quote
 
 
 
 
Maury Markowitz
Guest
Posts: n/a
 
      8th Dec 2008
On Dec 8, 3:49*pm, daisy2008 <daisy2...@discussions.microsoft.com>
wrote:
> I need an entire row deleted if column 2 on worksheet 3; date is one year
> later but is less then todays date. *I need this to run when my workbook is
> opened.
>
> Ex
> B4 January 2, 2008
> B5 November 4, 2007
> B6 December 26, 2007
> B7 December 5, 2007
>
> Row 5 *and row 7 are deleted when I open the workbook.


Well the opening the notebook is up to you. However, the code will be
similar to...

for i = 1 to ASMANYROWSASYOUCAREABOUT
theCell = Cells(2,i)
if abs(datediff("yyyy", theCell, date)) > 1 then
theCell.entirerow.delete
end if
next i

Maury
 
Reply With Quote
 
Otto Moehrbach
Guest
Posts: n/a
 
      8th Dec 2008
Daisy
Place this macro in the workbook module of your file. HTH Otto
Private Sub Workbook_Open()
Dim rColB As Range
Dim c As Long
With Sheets("3")
Set rColB = .Range("B4", .Range("B" & Rows.Count).End(xlUp))
For c = rColB.Count To 1 Step -1
If DateSerial(Year(Date), Month(rColB(c)), Day(rColB(c))) < Date
And _
Year(rColB(c)) + 1 = Year(Date) Then _
rColB(c).EntireRow.Delete
Next c
End With
End Sub
"daisy2008" <(E-Mail Removed)> wrote in message
news:39E49D7F-CED4-456D-8853-(E-Mail Removed)...
>I need an entire row deleted if column 2 on worksheet 3; date is one year
> later but is less then todays date. I need this to run when my workbook
> is
> opened.
>
> Ex
> B4 January 2, 2008
> B5 November 4, 2007
> B6 December 26, 2007
> B7 December 5, 2007
>
>
> Row 5 and row 7 are deleted when I open the workbook.
>
>



 
Reply With Quote
 
daisy2008
Guest
Posts: n/a
 
      9th Dec 2008
Thank you Otto

I'm getting a compile error:syntax error and then it highlighted

If Dateserial........

What am I doing wrong?
I have 1000 rows it will need to look through.

"Otto Moehrbach" wrote:

> Daisy
> Place this macro in the workbook module of your file. HTH Otto
> Private Sub Workbook_Open()
> Dim rColB As Range
> Dim c As Long
> With Sheets("3")
> Set rColB = .Range("B4", .Range("B" & Rows.Count).End(xlUp))
> For c = rColB.Count To 1 Step -1
> If DateSerial(Year(Date), Month(rColB(c)), Day(rColB(c))) < Date
> And _
> Year(rColB(c)) + 1 = Year(Date) Then _
> rColB(c).EntireRow.Delete
> Next c
> End With
> End Sub
> "daisy2008" <(E-Mail Removed)> wrote in message
> news:39E49D7F-CED4-456D-8853-(E-Mail Removed)...
> >I need an entire row deleted if column 2 on worksheet 3; date is one year
> > later but is less then todays date. I need this to run when my workbook
> > is
> > opened.
> >
> > Ex
> > B4 January 2, 2008
> > B5 November 4, 2007
> > B6 December 26, 2007
> > B7 December 5, 2007
> >
> >
> > Row 5 and row 7 are deleted when I open the workbook.
> >
> >

>
>
>

 
Reply With Quote
 
Otto Moehrbach
Guest
Posts: n/a
 
      9th Dec 2008
Daisy
You are probably the victim of line wrapping. This is always a problem
when code (a macro) is sent to someone in an email or a post. Excel is very
unforgiving with line wrapping. The DateSerial line is 3 lines to you and
me but is taken as one line by Excel. For this to work, the underline (_)
character must be the last character in the line. Rearrange that line so
that it is 3 lines with the underline character at the end of the first 2
lines. Try that. HTH Otto
"daisy2008" <(E-Mail Removed)> wrote in message
news:ED091C46-0E9D-4730-801A-(E-Mail Removed)...
> Thank you Otto
>
> I'm getting a compile error:syntax error and then it highlighted
>
> If Dateserial........
>
> What am I doing wrong?
> I have 1000 rows it will need to look through.
>
> "Otto Moehrbach" wrote:
>
>> Daisy
>> Place this macro in the workbook module of your file. HTH Otto
>> Private Sub Workbook_Open()
>> Dim rColB As Range
>> Dim c As Long
>> With Sheets("3")
>> Set rColB = .Range("B4", .Range("B" & Rows.Count).End(xlUp))
>> For c = rColB.Count To 1 Step -1
>> If DateSerial(Year(Date), Month(rColB(c)), Day(rColB(c))) <
>> Date
>> And _
>> Year(rColB(c)) + 1 = Year(Date) Then _
>> rColB(c).EntireRow.Delete
>> Next c
>> End With
>> End Sub
>> "daisy2008" <(E-Mail Removed)> wrote in message
>> news:39E49D7F-CED4-456D-8853-(E-Mail Removed)...
>> >I need an entire row deleted if column 2 on worksheet 3; date is one
>> >year
>> > later but is less then todays date. I need this to run when my
>> > workbook
>> > is
>> > opened.
>> >
>> > Ex
>> > B4 January 2, 2008
>> > B5 November 4, 2007
>> > B6 December 26, 2007
>> > B7 December 5, 2007
>> >
>> >
>> > Row 5 and row 7 are deleted when I open the workbook.
>> >
>> >

>>
>>
>>



 
Reply With Quote
 
daisy2008
Guest
Posts: n/a
 
      9th Dec 2008



Otto, you are so great!!!!!

Thank you so very much.
Daisy




"Otto Moehrbach" wrote:

> Daisy
> You are probably the victim of line wrapping. This is always a problem
> when code (a macro) is sent to someone in an email or a post. Excel is very
> unforgiving with line wrapping. The DateSerial line is 3 lines to you and
> me but is taken as one line by Excel. For this to work, the underline (_)
> character must be the last character in the line. Rearrange that line so
> that it is 3 lines with the underline character at the end of the first 2
> lines. Try that. HTH Otto
> "daisy2008" <(E-Mail Removed)> wrote in message
> news:ED091C46-0E9D-4730-801A-(E-Mail Removed)...
> > Thank you Otto
> >
> > I'm getting a compile error:syntax error and then it highlighted
> >
> > If Dateserial........
> >
> > What am I doing wrong?
> > I have 1000 rows it will need to look through.
> >
> > "Otto Moehrbach" wrote:
> >
> >> Daisy
> >> Place this macro in the workbook module of your file. HTH Otto
> >> Private Sub Workbook_Open()
> >> Dim rColB As Range
> >> Dim c As Long
> >> With Sheets("3")
> >> Set rColB = .Range("B4", .Range("B" & Rows.Count).End(xlUp))
> >> For c = rColB.Count To 1 Step -1
> >> If DateSerial(Year(Date), Month(rColB(c)), Day(rColB(c))) <
> >> Date
> >> And _
> >> Year(rColB(c)) + 1 = Year(Date) Then _
> >> rColB(c).EntireRow.Delete
> >> Next c
> >> End With
> >> End Sub
> >> "daisy2008" <(E-Mail Removed)> wrote in message
> >> news:39E49D7F-CED4-456D-8853-(E-Mail Removed)...
> >> >I need an entire row deleted if column 2 on worksheet 3; date is one
> >> >year
> >> > later but is less then todays date. I need this to run when my
> >> > workbook
> >> > is
> >> > opened.
> >> >
> >> > Ex
> >> > B4 January 2, 2008
> >> > B5 November 4, 2007
> >> > B6 December 26, 2007
> >> > B7 December 5, 2007
> >> >
> >> >
> >> > Row 5 and row 7 are deleted when I open the workbook.
> >> >
> >> >
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Otto Moehrbach
Guest
Posts: n/a
 
      9th Dec 2008

You're welcome. Thanks for the feedback. Otto
"daisy2008" <(E-Mail Removed)> wrote in message
news:3C8F901B-71BF-49EB-BB76-(E-Mail Removed)...
>
>
> Otto, you are so great!!!!!
>
> Thank you so very much.
> Daisy
>
>
>
>
> "Otto Moehrbach" wrote:
>
>> Daisy
>> You are probably the victim of line wrapping. This is always a
>> problem
>> when code (a macro) is sent to someone in an email or a post. Excel is
>> very
>> unforgiving with line wrapping. The DateSerial line is 3 lines to you
>> and
>> me but is taken as one line by Excel. For this to work, the underline
>> (_)
>> character must be the last character in the line. Rearrange that line so
>> that it is 3 lines with the underline character at the end of the first 2
>> lines. Try that. HTH Otto
>> "daisy2008" <(E-Mail Removed)> wrote in message
>> news:ED091C46-0E9D-4730-801A-(E-Mail Removed)...
>> > Thank you Otto
>> >
>> > I'm getting a compile error:syntax error and then it highlighted
>> >
>> > If Dateserial........
>> >
>> > What am I doing wrong?
>> > I have 1000 rows it will need to look through.
>> >
>> > "Otto Moehrbach" wrote:
>> >
>> >> Daisy
>> >> Place this macro in the workbook module of your file. HTH Otto
>> >> Private Sub Workbook_Open()
>> >> Dim rColB As Range
>> >> Dim c As Long
>> >> With Sheets("3")
>> >> Set rColB = .Range("B4", .Range("B" & Rows.Count).End(xlUp))
>> >> For c = rColB.Count To 1 Step -1
>> >> If DateSerial(Year(Date), Month(rColB(c)), Day(rColB(c)))
>> >> <
>> >> Date
>> >> And _
>> >> Year(rColB(c)) + 1 = Year(Date) Then _
>> >> rColB(c).EntireRow.Delete
>> >> Next c
>> >> End With
>> >> End Sub
>> >> "daisy2008" <(E-Mail Removed)> wrote in message
>> >> news:39E49D7F-CED4-456D-8853-(E-Mail Removed)...
>> >> >I need an entire row deleted if column 2 on worksheet 3; date is one
>> >> >year
>> >> > later but is less then todays date. I need this to run when my
>> >> > workbook
>> >> > is
>> >> > opened.
>> >> >
>> >> > Ex
>> >> > B4 January 2, 2008
>> >> > B5 November 4, 2007
>> >> > B6 December 26, 2007
>> >> > B7 December 5, 2007
>> >> >
>> >> >
>> >> > Row 5 and row 7 are deleted when I open the workbook.
>> >> >
>> >> >
>> >>
>> >>
>> >>

>>
>>
>>



 
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
deleting an entire row if the cell in col A is empty =?Utf-8?B?WmIgS29ybmVja2k=?= Microsoft Excel Programming 1 8th Mar 2007 01:18 AM
Deleting entire row.... final question Pam Field Microsoft Excel Discussion 3 23rd Jul 2006 01:29 PM
Deleting Entire Page =?Utf-8?B?RGFubyBPJ0Q=?= Microsoft Word Document Management 4 21st Jun 2005 08:52 PM
Code for deleting entire row gregork Microsoft Excel Programming 2 4th Jul 2004 12:13 PM
Deleting entire rows Ed C Microsoft Excel Programming 2 18th Jun 2004 02:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:14 PM.