![]() |
|
|
|||||||
| 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 |
|
New Member
Join Date: May 2002
Location: london
Posts: 17
|
Hello
Does any one know how to get a macro to perform a task on all worksheets in a workbook without having to specify each sheet individualy.i.e I have a macro that deletes a row based on a certain criteria and I want it to run in all the worksheets in a workbook. Also is there an esay way of specifiying a macro to delete all rows where dates in a specific row/cell are older than todays? I have messed around with now and today function and came up with the following but it's a bit long winded. The way I have done it currently is: Sub Deleterows() Dim i As Double Worksheets("Text").Cells(20, 1) = "=today()" ' INSERTS CURRENT DATE IN THAT CELL Worksheets("non").Select For i = 100 To 1 Step -1 If Cells(i, 1).Value < Worksheets("Text").Cells(20, 1) Then _ Cells(i, 1).EntireRow.Delete Next i Thanks very much. Hamnet |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
Maybe this will work. I did not test it.
Tom |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sunny, spring-like Hull
Posts: 3,339
|
Just a couple of additions Tom: -
Sub Deleterows() Dim i As Integer, sh As Worksheet Application.ScreenUpdating = False For Each sh In Worksheets For i = 100 To 1 Step -1 If IsDate(sh.Cells(i, 1)) Then If Not DateDiff("d", sh.Cells(i, 1).Value, Now) = 0 Then _ sh.Cells(i, 1).EntireRow.Delete End If Next i Next sh Application.ScreenUpdating = True End Sub |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|