How to select a perioid between two dates?

Waimea

Active Member
Joined
Jun 30, 2018
Messages
465
Office Version
  1. 365
Platform
  1. Windows
Hi,

in column G I have a range of dates, mostly without breaks.


Date
2021-09-15​
2021-09-15​
2021-09-14​
2021-09-14​
2021-09-14​
2021-09-13​
2021-09-13​
2021-09-13​
2021-09-12​
2021-09-12​
2021-09-12​

How can I easily select a period of dates between to dates? I am trying to use one cell with "From date" and one cell with "To date",

Ex. If I wanted to select all dates between 2021-09-15 and 2021-09-13, and if left blank I would get all dates. And I will get all data in the other columns where the dates match.

From date: 2021-09-13

To date: 2021-09-15

All suggestions are welcome. Perhaps there is a better way using comboboxes or dropdowns for year, month and day? Or slicers?

EDIT:

I spelled "period" wrong in the thread title, perhaps someone could correct it?
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Select as in filter? As in create an array for a formula? Select to copy? Something else?
 
Upvote 0
Hi jasonb75,

thank you for your reply.

I want to create a new sheet/table with the data that is between the two selected dates. If omitted, I would get all data.

In a later step I want to do some calculations on the data that is between the two date ranges.

In my data I can have more then one date range. So you could say that the date ranges are repeated but with different data in the other columns.

Ex.

2019-09-20​
2019-09-19​
2019-09-19​
2019-09-18​
2019-09-17​
2019-09-13​
2019-09-13​
2019-09-13​
2019-09-13​
2019-09-13​
2019-09-12​
2019-09-12​
2019-09-12​
2019-09-12​
2021-09-15​
2021-09-14​
2021-09-14​
2021-09-15​


Does this make sense? In my date column the date ranges can exist multiple times, so I could have data from 2019-09-10 to 2019-09-25 and then data is 2019-09-10 to 2019-09-25 again but with different other data. I want to get the data in all the date ranges that are valid.
 
Upvote 0
Maybe you could filter the original by date using the reference dates as start and end points, then copy and paste to a new sheet?
 
Upvote 0
Column G type is date?
How many possible rows?
What columns is copied?
What do You mean by: and if left blank I would get all dates
 
Upvote 0
You could do something like this with formulas, but it appears that your data is not in any order so you might encounter problems with anything other than filtering. (column B in the example contains random values for testing).
Book1
ABCDEF
12019-09-200.3324142FromResults
22019-09-190.574912019-09-162019-09-170.7646837
32019-09-190.4750512To2019-09-130.2871864
42019-09-180.61339572021-09-142019-09-130.2856923
52019-09-170.76468372019-09-130.3521906
62019-09-130.28718642019-09-130.5912346
72019-09-130.28569232019-09-130.7903674
82019-09-130.35219062019-09-120.7465116
92019-09-130.59123462019-09-120.9693586
102019-09-130.79036742019-09-120.2849126
112019-09-120.74651162019-09-120.1309111
122019-09-120.96935862021-09-150.0083453
132019-09-120.28491262021-09-140.0070639
142019-09-120.13091112021-09-140.8008066
152021-09-150.0083453
162021-09-140.0070639
172021-09-140.8008066
182021-09-150.6161982
19
Sheet4
Cell Formulas
RangeFormula
E2:F14E2=INDEX(A:A,IF(D2="",1,XMATCH(D2,A:A,1,1))):INDEX(B:B,IF(D4="",XMATCH(1E+100,A:A,-1,2),XMATCH(D4,A:A,1,-1)))
Dynamic array formulas.
 
Upvote 0
Column G type is date?
How many possible rows?
What columns is copied?
What do You mean by: and if left blank I would get all dates
Hi Tupe77,

thank you for your reply!

I have 10 000 x 80 rows at the most.

Say I have data from


2019-08-01

to

2019-09-01.

I would like to select e.x. dates 2019-08-01 to 2019-08-08 and only get data within this range. But if I leave the from and to blank, I would get data from 2019-08-01 to 2019-09-01.
 
Upvote 0
Hi jasonb75,

thank you for your reply.

When you say filtering, do you mean filter and/or advanced filter?

Perhaps I could create a sub that checks if a date is within the selected date period?

Perhaps create an array with the date range in and then load the data from the date periods in another array and check item per item.
 
Upvote 0
I found this snipppet here Get Array of Dates Between 2 Dates

VBA Code:
Dim dtDate as Date, dtStartDate as date, dtEndDate as Date

dtStartDate = #8/1/2019#
dtEndDate = #8/31/2019#

For dtDate = dtStartDate To dtEndDate
    'code to do each date
Next dtDate

Perhaps this could be a part of my code?
 
Upvote 0
When you say filtering, do you mean filter and/or advanced filter?
Regular filter. Click the filter arrow at the top of the column, then go to Date Filters > Between and choose your dates. Copy and paste your data to a new sheet, all while recording a macro so that you have the base code to work from.
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,605
Members
449,089
Latest member
Motoracer88

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