![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Apr 2002
Posts: 76
|
In column I of a sheet I am working on I have lists of dates. What I need to happen is that if the date is more than 5 days old, the entire row it is on is deleted Does anyone have any ideas? I'm sure I've seen something like it before Janie |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
Hi
Right click on your sheet tab, choose view code, place this in there... Whenever you open your sheet, this code will be run.
Tom [ This Message was edited by: TsTom on 2002-04-26 01:54 ] |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Apr 2002
Posts: 76
|
That's great Tom, thanks, but is there any way of doing it every time the actual workbook is opened? The sheet is called "Data" but it's not actually accessible to the users so they won't be able to open it Janie |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Apr 2002
Posts: 76
|
Hi there, I've managed to get this code to work during the workbook open event. It's great except that I was wrong, it's not column I, it's column J. Do I need to change the reference to J or to 10 as that's the column number? Janie |
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Apr 2002
Posts: 76
|
Now it's saying Type Mismatch???? |
|
|
|
|
|
#6 | |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
Quote:
|
|
|
|
|
|
|
#7 |
|
Board Regular
Join Date: Apr 2002
Posts: 76
|
I've tried all ways now, and all I get is Type Mismatch???
This is the code: Private Sub Workbook_Open() Dim c For Each c In Sheets("Sheet2").UsedRange If c.Column = 10 And IsDate(c) = True And _ Now > c + 5 Then Rows(c.Row).EntireRow.Delete Next End Sub Janie [ This Message was edited by: buntykins on 2002-04-26 02:48 ] |
|
|
|
|
|
#8 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
I could not duplicate your error... It appears that you did not change the sheet name. If your sheet name is "Data" then this should work... Try this Tom [ This Message was edited by: TsTom on 2002-04-26 02:52 ] |
|
|
|
|
|
#9 |
|
Board Regular
Join Date: Apr 2002
Posts: 76
|
This is crazy, it still won't work??? I get runtime error 13 Type Mismatch all the time and it highlights this part: If c.Column = 10 And IsDate(c) = True And _ Now > c + 5 Then .Rows(c.Row).EntireRow.Delete |
|
|
|
|
|
#10 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
If c.Column = 10 And IsDate(c) = True And _
Now > c + 5 Then .Rows(c.Row).EntireRow.Delete No error on my machine... Gotta go... Replace the above with this... If c.Column = 10 And IsDate(c.value) = True And _ Now > c.value + 5 Then .Rows(c.Row).EntireRow.Delete Tom |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|