Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default =now() -30 days

I would like to set up my worksheet so that if the date in column C is more
than 30 day ago, that entire row will be deleted. Can anyone help?

Thanks,
Steve
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default =now() -30 days

How strange!

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Target.Column = 3 Then
If Target.Value < Date - 30 Then
Target.EntireRow.Delete
End If
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.

--
HTH

Bob Phillips

"Steve" wrote in message
...
I would like to set up my worksheet so that if the date in column C is

more
than 30 day ago, that entire row will be deleted. Can anyone help?

Thanks,
Steve



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default =now() -30 days

From what I can tell this is set up for when I actually type a date in the
cell. i think I was unclear. Everyday I enter information in this worksheet
that must be saved for 30 days. What I would like it to do is be able to run
a macro that auto deletes all entries older than 30 days. For example, today
is June 1, I would like to auto delete all entries on or before May 2. The
column with the dates is column C.

Thanks again,
Steve

"Bob Phillips" wrote:

How strange!

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Target.Column = 3 Then
If Target.Value < Date - 30 Then
Target.EntireRow.Delete
End If
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.

--
HTH

Bob Phillips

"Steve" wrote in message
...
I would like to set up my worksheet so that if the date in column C is

more
than 30 day ago, that entire row will be deleted. Can anyone help?

Thanks,
Steve




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default =now() -30 days




Sub DeleteRows()
Dim i as Long, lastrow as Long
Dim cell as Range
set lastrow = cells(rows.count,3).End(xlup)
for i = lastrow to 2 step -1
set cell = cells(i,3)
if isdate(cell) then
if Date - cell.Value 30 then
cell.Entirerow.Delete
end if
end if
Next
End Sub


--
Regards,
Tom Ogilvy

"Steve" wrote in message
...
From what I can tell this is set up for when I actually type a date in the
cell. i think I was unclear. Everyday I enter information in this

worksheet
that must be saved for 30 days. What I would like it to do is be able to

run
a macro that auto deletes all entries older than 30 days. For example,

today
is June 1, I would like to auto delete all entries on or before May 2. The
column with the dates is column C.

Thanks again,
Steve

"Bob Phillips" wrote:

How strange!

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Target.Column = 3 Then
If Target.Value < Date - 30 Then
Target.EntireRow.Delete
End If
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.

--
HTH

Bob Phillips

"Steve" wrote in message
...
I would like to set up my worksheet so that if the date in column C is

more
than 30 day ago, that entire row will be deleted. Can anyone help?

Thanks,
Steve






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default =now() -30 days

I am getting an error at:
set lastrow = cells(rows.count,3).End(xlup)

it is a compile error: Object required
"Tom Ogilvy" wrote:




Sub DeleteRows()
Dim i as Long, lastrow as Long
Dim cell as Range
set lastrow = cells(rows.count,3).End(xlup)
for i = lastrow to 2 step -1
set cell = cells(i,3)
if isdate(cell) then
if Date - cell.Value 30 then
cell.Entirerow.Delete
end if
end if
Next
End Sub


--
Regards,
Tom Ogilvy

"Steve" wrote in message
...
From what I can tell this is set up for when I actually type a date in the
cell. i think I was unclear. Everyday I enter information in this

worksheet
that must be saved for 30 days. What I would like it to do is be able to

run
a macro that auto deletes all entries older than 30 days. For example,

today
is June 1, I would like to auto delete all entries on or before May 2. The
column with the dates is column C.

Thanks again,
Steve

"Bob Phillips" wrote:

How strange!

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Target.Column = 3 Then
If Target.Value < Date - 30 Then
Target.EntireRow.Delete
End If
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.

--
HTH

Bob Phillips

"Steve" wrote in message
...
I would like to set up my worksheet so that if the date in column C is
more
than 30 day ago, that entire row will be deleted. Can anyone help?

Thanks,
Steve








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default =now() -30 days

Try

Sub DeleteRows()
Dim i as Long, lastrow as Long
Dim cell as Range
lastrow = cells(rows.count,3).End(xlup).Row
for i = lastrow to 2 step -1
set cell = cells(i,3)
if isdate(cell) then
if Date - cell.Value 30 then
cell.Entirerow.Delete
end if
end if
Next
End Sub


--
HTH

Bob Phillips

"Steve" wrote in message
...
I am getting an error at:
set lastrow = cells(rows.count,3).End(xlup)

it is a compile error: Object required
"Tom Ogilvy" wrote:




Sub DeleteRows()
Dim i as Long, lastrow as Long
Dim cell as Range
set lastrow = cells(rows.count,3).End(xlup)
for i = lastrow to 2 step -1
set cell = cells(i,3)
if isdate(cell) then
if Date - cell.Value 30 then
cell.Entirerow.Delete
end if
end if
Next
End Sub


--
Regards,
Tom Ogilvy

"Steve" wrote in message
...
From what I can tell this is set up for when I actually type a date in

the
cell. i think I was unclear. Everyday I enter information in this

worksheet
that must be saved for 30 days. What I would like it to do is be able

to
run
a macro that auto deletes all entries older than 30 days. For example,

today
is June 1, I would like to auto delete all entries on or before May 2.

The
column with the dates is column C.

Thanks again,
Steve

"Bob Phillips" wrote:

How strange!

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Target.Column = 3 Then
If Target.Value < Date - 30 Then
Target.EntireRow.Delete
End If
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.

--
HTH

Bob Phillips

"Steve" wrote in message
...
I would like to set up my worksheet so that if the date in column

C is
more
than 30 day ago, that entire row will be deleted. Can anyone help?

Thanks,
Steve








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to pull <=14 Days, <=30 Days, 30 Days from a date column Ken Excel Discussion (Misc queries) 3 October 23rd 09 12:53 AM
Employee days worked (-Holidays, -weekends, Snow Days, etc) Denise Excel Discussion (Misc queries) 2 December 31st 08 04:37 PM
Calc days between two dates and exclude leap year days scoz Excel Worksheet Functions 5 November 23rd 07 03:58 PM
Conditional Formatting Dates calculating 10 days and 30 days from a certain date Sioux[_2_] Excel Worksheet Functions 2 October 11th 07 02:04 PM
COUNT how many ROWS ago out of 10 days that the highest high in 10 days was made rhhince Excel Worksheet Functions 1 January 14th 07 09:56 PM


All times are GMT +1. The time now is 03:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"