Enter a date, find the period..?

towners

Board Regular
Joined
Mar 12, 2009
Messages
225
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I'me entering a date and want to find the period from a set of data. Can anyone help?

ColA (period number) Col B (from date) Col C (to date)

Period 1; 3/12/10; 31/12/10
Period 2; 3/1/11; 28/1/11
Period 3; 3/2/11; 28/2/11

So I want to put some code into my userform VBA that takes the date and find the period to then add to my worksheet.

i.e. date = 5/12/10, Period = 1

Any help gratefully received...

Thanks

Paul
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
If you have "TextBox1 " to enter your Date & TextBox2 to receive the result.
Then Place this in a Commandbutton on the form.
Code:
Private Sub CommandButton1_Click()
Dim Rng As Range
Dim Dn As Range
Dim dt As Date
Dim Fd As Boolean
dt = TextBox1
Set Rng = Range(Range("A1"), Range("A" & rows.Count).End(xlUp))
For Each Dn In Rng
    If Dn(, 2) <= dt And Dn(, 3) >= dt Then
        TextBox2 = Dn
        Fd = True
         Exit For
    End If
Next Dn
If Fd = False Then TextBox2 = "No Match Found"
End Sub
Regards Mick
 
Upvote 0
Any ideas how I can also get the same result in a worksheet?

Regards

Paul
 
Upvote 0
Can the period 1 be December, period 2 be January, and period 3 be February, or does an error message have to occur if the 1,2,29,30, or 31 are the day?
 
Upvote 0
Hi,

No, the periods are accounting periods. There are 13 periods in a year each has 28 days so the from - to dates change each year...
 
Upvote 0
If the date is in b5, then
=IF(MONTH(B5)=12,1,MONTH(B5)-1)

If you want to word period then
=if(month(b5)=12,"Period 1","Period "&month(b5-1)
 
Upvote 0
Hi,

Not sure that will work. I have a look up table over 3 columns: Period Number, From date, To date. I want to enter a date and have the worksheet check the look up table and populate the associated period in the cell next to my date.
 
Upvote 0
If the first day the fiscal year is 12/3/2010, and each of the periods if for 28 days, and the date is in cell A3, then the period the date is in is =int((a3-41079)/28) + 1. This subtract 12/3/2010 from the date, and finds out which 28 day period it is in. The integer function truncates the fraction, and adding one rounds up the result. 41079 is the numerical representation of 12/3/2010.

Hopefully I am understanding the situation right.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,726
Members
452,939
Latest member
WCrawford

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