change to macro that autofilter's rows based on entered ship date

steve400243

Active Member
Joined
Sep 15, 2016
Messages
429
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello, The attached has a working macro, shown below, that filters out rows when a date is entered into Cell "B1" It hides any row that does not match the Ship date in column "E". I would like the macro changed to show all data, regardless of ship date, when the cell B1 is left empty. Thanks for the help!

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Range("B1"), Target) Is Nothing Then
    Application.EnableEvents = False
        With Range("A3:E3")
            .AutoFilter 5, Format(Range("B1").Value, "mmm-dd")
        End With
    End If
    Application.EnableEvents = True
End Sub

Herban Cowboy Test.xlsm
ABCDEFGHIJKN
1Ship DateWed.Apr.27.2022cc:426cc:025cc:426cc:430cc:473
2 Each: $5.25$12.50$1.05$0.25$22.00
3Order NumberPurchase OrderDestinationOrder DateShip DateCarrierOrder ChargeBOL Fee Carton Out Charge FedEx LabelsFedEx Pallet Weekly Charges
42970772456808572UNFI - AURORAApr-20Apr-2711221$ 42.35
52970773476811839UNFI - LANCASTERApr-20Apr-2711621$ 46.55
62970776466789884UNFI - RIDGEFIELDApr-20Apr-2711121$ 41.30
9Total$ 130.20
Data
Cell Formulas
RangeFormula
N4:N6N4=[Order Charge]*$G$2+[BOL Fee]*$H$2+[Carton Out Charge]*$I$2+[FedEx Labels]*$J$2+[FedEx Pallet]*$K$2
N9N9=SUBTOTAL(109,[Weekly Charges])
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A4:A8Cell ValueduplicatestextNO
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Try replacing your Worksheet_Change code with this:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Range("B1"), Target) Is Nothing Then
        Application.EnableEvents = False
        If Range("B1") <> "" Then
            With Range("A3:E3")
                .AutoFilter 5, Format(Range("B1").Value, "mmm-dd")
            End With
        ElseIf Range("B1") = "" Then
            Me.ShowAllData
        End If
    End If
    Application.EnableEvents = True
End Sub
 
Upvote 0
That gives me a Run time error '1004': Method "Showalldata' of object'_worksheet' failed
 
Upvote 0
That gives me a Run time error '1004': Method "Showalldata' of object'_worksheet' failed
Strange - it worked for me. Try changing this line:

VBA Code:
Me.ShowAllData

to this:

VBA Code:
ActiveSheet.ShowAllData
 
Upvote 0
Nope, still getting the error - and it highlights that line

VBA Code:
ActiveSheet.ShowAllData
 
Upvote 0
OK, here we go:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Range("B1"), Target) Is Nothing Then
        Application.EnableEvents = False
        If Range("B1") <> "" Then
            With Range("A3:E3")
                .AutoFilter 5, Format(Range("B1").Value, "mmm-dd")
            End With
        ElseIf Range("B1") = "" Then
            With Range("A3:E3")
                .AutoFilter 5, "<>"
            End With
        End If
    End If
    Application.EnableEvents = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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