Filtering Invoices by Date

morrisgr

Board Regular
Joined
Dec 17, 2005
Messages
62
Can someone please point me in the right direction?
I have a list of 500 invoices dated from Jan1 to Dec31.
I want a Macro to filter the list to include those dated between Jul1 and Sept30 (these dates to be variable and input by the user).

I have a long winded way of doing it by reformatting the dates to "General", which makes them a number, and then comparing each row.
But it checks all 500 each time.
Is it possible to use xlBetween ?

Any guidance appreciated.
morrisg
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Thanks for the welcome, much appreciated.
The total data covers 5columns and 500 rows but the dates are in the Range("A5:A505").
There is a header row.THe Header is in A4 and, not surprisingly, is DATE.
Can you help?
morrisg
 
Upvote 0
How about this?
Code:
Option Explicit

Sub FilterInvoices()
Dim FilterRange As Range
Dim BegDate As String, EndDate As String
Dim NumberFormat As String

Set FilterRange = Range("A4:A505")
NumberFormat = Range("A5").NumberFormat
On Error GoTo ErrorRoutine
BegDate = CDate(InputBox("Enter beginning date"))
EndDate = CDate(InputBox("Enter ending date"))
FilterRange.AutoFilter Field:=1, Criteria1:=">=" & Format(BegDate, NumberFormat), Operator:=xlAnd _
        , Criteria2:="<=" & Format(EndDate, NumberFormat)
Exit Sub

ErrorRoutine:
    MsgBox "Macro error encountered"
End Sub
 
Upvote 0
Filtering Invoices...a bit more

Hi Barrie.
Excellent.....thanks.
I didn't know how to set Criteria2.....
As I'm sure happens quite a lot in these circumstances, I have a new query.
How can I copy the filtered Rows onto another sheet?
I know how to copy and paste but how do I select the filtered rows?

Thanks for the help, much appreciated.
Morris
 
Upvote 0
Filtering Invoices....done

Barrie.
Thanks again, I've managed to answer my own question.
Thanks
Morris
 
Upvote 0
If anyone's interested, here's the code to copy the filtered range:
Code:
FilterRange.Offset(1).Resize(FilterRange.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Copy _
    Destination:=Sheets("Sheet2").Range("A1")

NOTE - this will create an error if the filtered range is empty.
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,072
Latest member
DW Draft

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