Excel VBA表单日期验证 [英] Excel VBA Form Date validation

查看:87
本文介绍了Excel VBA表单日期验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚接触VBA,这是我第一次尝试表单...

我已经在Excel 2003中构建了VBA表单.和文本框,这些文本框存储在工作表中以供后续制表.我正在寻找如何验证已输入到文本框之一中的日期字段(具体来说,毫米介于1到12之间,日期介于1到31之间),然后将该日期存储到Excel电子表格中.

我可以将输入的值从文本框中强制输入到指定的工作表单元格中,但是使用Cells(Rowindex,6)= CaseDate.text时无法进行验证...我试图转换文本转换为具有以下代码行的日期,但会产生424个对象错误... ... Cells(Rowindex,6)= CDate(Format(CaseDate.text,"mm/dd/yy"))
是将文本转换为日期,我认为错误是因为在Sub中尚未将CaseDate定义为变量(?)...我还尝试将Public CaseDate用作日期,但仍然出现424错误...

我还从书本来源复制了Sub过程,但这无济于事...有人可以帮助我吗?

I'm relatively new to VBA and this is my first form attempt...

I have built a VBA Form in Excel 2003.  I am capturing a number of fields, several from dropdown lists and textboxes which are stored in a Worksheet for subsequent tabulation.  I am looking for how to validate a date field (specifically that the mm is between 1-12, the day is between 1-31) that has been entered into one of the text boxes and then store that date into the Excel spreadsheet . 

I can force the entered value from the textbox into the specified Worksheet Cell, but it has no validation using Cells(Rowindex,6) = CaseDate.text ...  I've tried to convert the text into a date with the following line of code but that produces a 424 Object error...  Cells(Rowindex,6) = CDate(Format(CaseDate.text," mm/dd/yy"))
The thought is to convert the text into a date, I think the error is because the CaseDate has not been defined as a variable(?) in the Sub...  I've tried to Dim CaseDate as a Variant within the Sub and I've also tried to used Public CaseDate as Date and I still get the 424 error...

I've also copied a Sub procedure from a book source but that is no help...  Can someone assist me in what I'm doing incorrectly?

推荐答案

jldkb.欢迎来到这里的论坛.请注意,该论坛仅针对 VB.NET 问题,而非VBA.尽管您可能会在此处收到答案,但最好还是在专门针对VBA的论坛中发帖.请参阅此论坛顶部的即时贴以获取建议的论坛链接...

Hi jldkb.  Welcome to the forums here.  Please note that this forum is for VB.NET questions and not VBA.  While you may receive an answer here you might do better to post in a forum that is dedicated to VBA.  See the sticky thread at the top of this forum for suggested forum links...

http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/c147bae1-c9db-4ae8-9557-43713004cc94


Good luck!


这篇关于Excel VBA表单日期验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆