简体   繁体   English

Excel VBA-年初至今验证

[英]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. 例如,我的财政年度的开始是2012年7月1日,因此,如果我正在运行该月的2012年7月至2013年6月的报告,则输入的财务将不会返回错误消息。 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?" 但是,如果我正在运行的月度报告是“ 2013年7月”或“ 2013年8月”,而我输入的YTD是“ 2012年7月”,则我想提醒您说“您是否要重置输入的YTD?”

Thanks. 谢谢。

There is a lot you aren't explaining... your first example is a 12-month report, then later you mention monthly reports. 您没有很多解释...第一个示例是一份12个月的报告,然后您提到了月度报告。 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? 以您的示例为例,如果月度报表从2013年8月开始运行,则提示提示的用户输入是否总是错误,还是仅在某些时候?

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. 为什么不简单地对上一个和下一个20(?)个会计年度的第一天进行硬编码,并验证用户输入是否与其中一个相匹配。 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. 我实际上会建议进行单元内数据验证(针对由头几天组成的列表进行验证),但是您表示正在使用UserForm。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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