我正在为我所在地区的员工制作一个防错工作表。我们的系统需要通过Excel工作表提供。除了我已经添加的其他验证之外,我还需要将生日日期转换为格式YYYYMMDD
作为字符串/数字,因为在Excel上使用自定义格式将其转换为在上载时丢失系统上的错误(我猜它仍然将日期读作DD /月/年)。
因此,我正在尝试使用Worksheet_Change()
,因此当用户输入任何日期为DD/MM/YYYY
时,它会自动转换为所需的结果。
If Not Intersect(Target, Columns("G")) Is Nothing Then
On Error Resume Next
fecnacadd = Target.Address
fecnac = Target.Value
fecnacadd = Format(fecnac, "yyyymmdd")
Columns("G").NumberFormat = "General"
End If
这段代码在调试时很奇怪(正确显示'YYYYMMDD'),但按原样运行,在循环(?)中获取宏10秒,并删除单元格中的内容。
我的代码中的任何提示都表示赞赏。
解决了它和它的日期格式证明(与DD或MM的顺序无关)。还在评论中添加了建议。谢谢!
If Not Intersect(Target, Columns("G")) Is Nothing Then
Application.EnableEvents = False
On Error Resume Next
fecnacadd = Target.Address
fecnac = Format(Target.Value, "YYYYMMDD")
Target.Value = fecnac
Columns("G").NumberFormat = "General"
Application.EnableEvents = True
End If