简体   繁体   中英

Excel VBA - Year to Date validation

I have a variable input in my Userform for the start of the Financial Year. I want to be able to validate the entry, so that it will prompt the user if the date entered is not the a start date for a financial year.

Eg.The start of my Financial year is 01 Jul 2012, so if I was running a report for the month's Jul 2012-Jun 2013 the Financial is entered will not come back with an error message. But if the monthly report I'm running is "Jul 2013", or "Aug 2013", and my YTD entered is "Jul 2012", I want an alert to say "Do you want to reset your YTD entered?"

Thanks.

There is a lot you aren't explaining... your first example is a 12-month report, then later you mention monthly reports. Using your example, if the monthly report is running starts Aug 2013. Is the user input that raises the prompt ALWAYS wrong, or only sometimes?

Regardless, things like the first day of the year don't change. Why not simply hardcode the first day of the last & next 20 (?) fiscal years, and verify the user's input matches one of them. I would actually suggest in-cell Data Validation (validating against a List comprised of the first days) but you stated you were using a UserForm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM