来自文本string的VBA中的date格式

我有一个date格式的问题,我不能得到我的头。

我有两个date报告date,用户input格式是MM / DD / YYYY在电子表格上显示为(11/15/2017)。 这是从用户表单input的,只要求月份和date,但使用当前年份。

然后我有一系列代码validation数据行匹配ReportDate并生成信息。 要获取数据date,我需要查找一个文本stringfind一个单词PPP,并获得数字继续@符号。

我分别得到date和月份的值,因为在这个string中只有日/月是可见的,就像这个PPP@11/15 11/15一样

下面是我的代码的摘录,但它不是完整的脚本。

 Dim Year1 As Variant Dim Month1 As Variant Dim Day1 As Variant If Not IsError(Mid(PODRng, InStr(1, PODRng, "PPP", vbTextCompare) + 4, 5)) Then Year1 = Format(Now(), "YYYY") Month1 = Mid(PPPRng, InStr(1, PPPRng, "PPP", vbTextCompare) + 4, 2) Day1 = Mid(PPPRng, InStr(1, PPPRng, "PPP", vbTextCompare) + 7, 2) PPPTim = Day1 & "/" & Month1 & "/" & Year1 'PPPTim.NumberFormat = "MM/DD/YYYY" If PPPTim = ReportDate Then Cell.Offset(0, 49).Value = PPPTim ' ElseIf InStr(1, PODRng, "PPP", vbTextCompare) > 0 Then Cell.Offset(0, 49).Value = "Other Date" End If 

万一

数据源大概是3k-5k行,当它到达这个代码的时候,我已经经历了代码并破坏了它。 我可以确认当检查本地PPPTim和ReportDate都显示为15/11/2017,但比赛是通过为False。

希望有人可以帮忙?

这是你在找什么?

Dim podRNG As String,n1 As Integer,n2 As Integer,yourDate As Date

 podRNG = "PPP@11/15" n1 = InStr(podRNG, "@") + 1 n2 = InStr(podRNG, "/") + 1 PPPTim = CDate(Mid(podRNG, n1, n2 - n1 - 1) & "/" & Mid(podRNG, n2) & _ "/" & Format(Now(), "YYYY")) 

退货(在我的系统上):

2017年11月15日

…由于数据types是Datedate格式将根据您的区域设置而有所不同