office交流网--QQ交流群号

Access培训群:792054000         Excel免费交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

VBA 设置单元格只能输入日期类型的数据

2020-05-02 08:00:00
zstmtony
原创
4271
VBA 设置单元格只能输入日期类型的数据

Sub 设置选择区域必须输入日期()
    Range("A2:A20000").Select
    Selection.NumberFormatLocal = "yyyy-mm-dd"
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateDate, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="1/1/1980", Formula2:="12/31/2900"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = "请输入入库日期"
        .ErrorTitle = "出错了"
        .InputMessage = ""
        .ErrorMessage = "请输入正确的日期"
        .IMEMode = xlIMEModeNoControl
        .ShowInput = True
        .ShowError = True
    End With
End Sub
分享