Create Ranges of Dates and Return a Value in VBA Code

Denny57

Board Regular
Joined
Nov 23, 2015
Messages
247
Office Version
  1. 365
Platform
  1. Windows
I am looking to apply a value to a date which falls in a range of dates without creating a lookup table. Knowing the issues of using dates in VBA.
I would be interested in guidance of the best approach as there can be an initial 24 date ranges to be used so the lookup table would require 730 rows of information

Example
If "Date" is in the range 01/01/2025 to 28/01/2025 return a value of "Pay 1 2025"
If "Date" is in the range 29/01/2025 to 25/02/2025 return a value of "Pay 2 2025"

I have considered using IF, ELSEIF, THEN but am not sure if the date values will work.

For information.
The value of "Date" will be in a TextBox (txtDate) and formated as dd/mm/yyyy
The return value will be returned to another TextBox (txtPayPeriod)

Best process guidance would be very much appreciated
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Not sure about the textboxes but I hope this can give you an idea.
I see in your example your pay period is every 28 days, if that's the case, this formula will tell you the Pay Period like in your example by looking at the date in cell A1
Excel Formula:
="Pay " & INT((A1-DATE(YEAR(A1), 1, 1))/28)+1 & " " & YEAR(A1)
 
Upvote 0

Forum statistics

Threads
1,226,049
Messages
6,188,567
Members
453,484
Latest member
jlo1673

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