excel - Excel 日期选择器日期格式
问题描述
我遇到了一个问题,Excel 中的日期选择器似乎正在使用我正在搜索的日期的美国版本。
我正在尝试检查是否存在工作表,其中某个单元格范围内的日期存在于 DTpicker1 和 DTpicker2 的参数中。
谁能告诉我如何强制代码以英国格式检查日期?
Private Sub CommandButton1_Click()
Dim s As Worksheet, wb As Workbook
UserForm1.Hide
For Each s In Worksheets
If CBool(Application.CountIfs(s.Range("E11:E37"), ">" &
Format(DTPicker1.Value, "dd/mm/yy"), _ s.Range("E11:E37"), "<" &
Format(DTPicker2.Value, "dd/mm/yy"))) Then
If wb Is Nothing Then
s.Copy
Set wb = ActiveWorkbook
Else
s.Copy after:=wb.Worksheets(wb.Worksheets.Count)
End If
End If
Next s
If wb Is Nothing Then
MsgBox ("No Records Found")
Else
wb.SaveAs Filename:="Technicians - Batch Record Report" & Format(Date,
"ddmmyyyy"), _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
End If
End Sub
感谢@Jeeped,他让我走到了这一步!
更新:代码通过反转日期格式工作:
Private Sub CommandButton1_Click()
Dim s As Worksheet, wb As Workbook
UserForm1.Hide
For Each s In Worksheets
If CBool(Application.CountIfs(s.Range("E11:E37"), ">" &
Format(DTPicker1.Value, "mm/dd/yy"), _ s.Range("E11:E37"), "<" &
Format(DTPicker2.Value, "mm/dd/yy"))) Then
If wb Is Nothing Then
s.Copy
Set wb = ActiveWorkbook
Else
s.Copy after:=wb.Worksheets(wb.Worksheets.Count)
End If
End If
Next s
If wb Is Nothing Then
MsgBox ("No Records Found")
Else
wb.SaveAs Filename:="Technicians - Batch Record Report" & Format(Date,
"ddmmyyyy"), _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
End If
End Sub
解决方案
您可以手动强制检查
If dateValue.NumberFormat <> "mm/dd/yyyy" Then '<-- provide the date format to validate with
推荐阅读
- java - 如果我的命令映射值的最后一段表示关于 jsp 文件视图名称,我如何获得最后一段 url?
- linux - 使用 PAT 进行 GitHub 身份验证
- c# - 调用外部变量时出现 NullReferenceException
- twitter-bootstrap - 模态轮播 Bootstrap 5 没有显示正确的图像
- typescript - 离子存储:TypeError:无法读取未定义的属性“get”
- laravel - 如何在 vue 中分离两个组件仪表板和登录页面
- json - github api "message":"Problems parblems parsing JSON" for large Base64 string
- reactjs - React useEffect 延迟运行
- delphi - Delphi“绝对”关键字
- html - 将单独的设计应用于 css 中的其他元素