Macro Question

Beekman

Board Regular
Joined
Nov 7, 2008
Messages
64
Below is part of my macro that works o.k.

Sheets("MONDAY").Select
Application.ScreenUpdating = False
With Range("A10", Range("A" & Rows.Count).End(xlUp))
.AutoFilter Field:=1, Criteria1:="=4027"
On Error Resume Next
.Offset(1).Resize(.Rows.Count - 1) _
.SpecialCells(xlCellTypeVisible).EntireRow.Delete
On Error GoTo 0
.AutoFilter
End With
Application.ScreenUpdating = False
With Range("A10", Range("A" & Rows.Count).End(xlUp))
.AutoFilter Field:=1, Criteria1:="=4100"
On Error Resume Next
.Offset(1).Resize(.Rows.Count - 1) _
.SpecialCells(xlCellTypeVisible).EntireRow.Delete
On Error GoTo 0
.AutoFilter
End With

The macro goes on repeating with the criterial value changing.It also goes onto "Tuesday", "Wednesday", "Thursday", "Friday"
Is there a better and shorter way of doing the above and get the same result.

Many thanks in advance.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Try

Code:
For Each ws In Sheets(Array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday"))
    With ws
        With .Range("A10", .Range("A" & Rows.Count).End(xlUp))
            .AutoFilter Field:=1, Criteria1:="=4027"
            On Error Resume Next
            .Offset(1).Resize(.Rows.Count - 1) _
            .SpecialCells(xlCellTypeVisible).EntireRow.Delete
            On Error GoTo 0
            .AutoFilter
        End With
        With .Range("A10", .Range("A" & Rows.Count).End(xlUp))
            .AutoFilter Field:=1, Criteria1:="=4100"
            On Error Resume Next
            .Offset(1).Resize(.Rows.Count - 1) _
            .SpecialCells(xlCellTypeVisible).EntireRow.Delete
            On Error GoTo 0
            .AutoFilter
        End With
    End With
Next ws
 
Upvote 0
Thanks VoG . Your Version works fine if you want the same criterial for each day, but i was seeing if you can condense the repeating of the eg

Application.ScreenUpdating = False
With Range("A10", Range("A" & Rows.Count).End(xlUp))
.AutoFilter Field:=1, Criteria1:="=4130"
On Error Resume Next
.Offset(1).Resize(.Rows.Count - 1) _
.SpecialCells(xlCellTypeVisible).EntireRow.Delete
On Error GoTo 0
.AutoFilter
End With
Application.ScreenUpdating = False
With Range("A10", Range("A" & Rows.Count).End(xlUp))
.AutoFilter Field:=1, Criteria1:="=4131"
On Error Resume Next
.Offset(1).Resize(.Rows.Count - 1) _
.SpecialCells(xlCellTypeVisible).EntireRow.Delete
On Error GoTo 0
.AutoFilter
End With

when I have multiple "Criterial" values for each day, but different ones for each day of the week
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,176
Members
452,893
Latest member
denay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top