Need a code for date checking

andrewb90

Well-known Member
Joined
Dec 16, 2009
Messages
1,077
Here is what I am looking for (Just have no idea how to convert it to a macro)

with the sheet 'Daily'
if C9 is greater than any cell in range sheet 'Setup' F18:F41
then Daily H9 will equal E18:E41+1

As an example
if C9 > Setup!F18, then H9 = Setup!E19

but if C9 > Setup!F19, then H9 would = Setup!E20

The macro would scan the entire range (F18:41) and the row that it was higher than (the greatest row) it would copy the text of the column E one cell down.

C9 and Column F are dates, FYI

Any insight would be very helpful!!!

Thanks,
Andrew
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
What if C9 is greater than more than one value in range Setup!F18:F41?
What if C9 is not greater than any values in range Setup!F18:F41?
Can there be any blank values in range Setup!F18:F41?
If so, how are they to be handled?
 
Upvote 0
If the c9 is greater than more than one value, it would be the most recent.
Let's say F18 = 02/04/12 and F19 = 03/07/12 and C9 = 03/09/12 than E20 would be the cell we want.

If c9 is not greater than any within range I would want a message box to appear and then I would send the user the the 'settings' sheet.

There should not be any blank values, if So a message box and sending the user to the settings sheet.

To give a little clarity: here is an example of my range:
E F
18 Period 1 2/6/2012
19 Period 2 3/5/2012
20 Period 3 4/2/2012
21 Period 4 5/7/2012
22 Period 5 6/4/2012
23 Period 6 7/2/2012
24 Period 7 8/6/2012
25 Period 8 9/3/2012
26 Period 9 10/1/2012
27 Period 10 11/5/2012
28 Period 11 12/3/2012
29 Period 12 12/31/2012
These are the ending date for accounting periods. This first part is 2012. So if C9 is a date between 3/5/12 and 4/2/12 then it would be period 3. In other words Period 3 runs from 3/6/12 - 4/1/12. I figured it would be easier to just look at what it is higher than and do the appropriate cell in relation to the date, but if you have a different idea that might be better/easier I'm all for it.
 
Upvote 0
Hello Andrew,

Here is an array formula you can put into cell 'Daily'H9. After you copy the formula into the cell, use Ctrl+Shift+Enter to confirm it. After you do this, you will see the formula enclosed in braces { }.

=INDEX('Setup'!$E$18:$E$40,MATCH(1,--(C9>='Setup'!F18:F40)*--(C9<'Setup'!F19:F41),0),1)
 
Last edited:
Upvote 0
The formula seems to work but it appears to be off.

with C9 = 3/27/2012 my formula in H9 should return a value of 'Period 3'. Instead it is returning 'Period 2'. I tried other dates and it seems to be behind by one period (or one cell in column E)
 
Upvote 0
If you just need to move one cell down from what Leith's formula returns, just use the Offset function, i.e.
Code:
=OFFSET(INDEX(Setup!$E$18:$E$40,MATCH(1,--(C9>=Setup!F18:F40)*--(C9 < Setup!F19:F41),0),1),1,0)<?XML:NAMESPACE PREFIX = Setup!F19 /><Setup!F19:F41),0),1),1,0)<?XML:NAMESPACE PREFIX="Setup!F19"></Setup!F19:F41),0),1),1,0)<?XML:NAMESPACE><Setup!F19:F41),0),1),1,0)< p>
(using Ctrl+Shift+Enter to confirm)</Setup!F19:F41),0),1),1,0)<>
 
Upvote 0
Good Stuff, I just used this. The only thing that I changed is the sign on the first matrices

=INDEX($B$9:$F$82,MATCH(1,--(H7<=$C$9:$C$80)*--(H7<$C$35:$C$81),0),5)


It took me a bit to find it, but it should be noted that there is an offset to the ranges.

(H7<=$C$9:$C$80)*--(H7<$C$10:$C$81)

It also took me a bit to understand why the match was = "1":confused: and it was a slick way of making things ="True"
 
Upvote 0

Forum statistics

Threads
1,225,156
Messages
6,183,228
Members
453,152
Latest member
ChrisMd

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