Vba在一个单元中分隔多个date

我试图将一个单元格中的多个date分隔成多个单元格,在转置区域中包含一个date,然后将它们作为单独的条目粘贴回原始区域。

一个示例单元格的date可能存储为10/1110/1110/13或10/310/310/410/5。 第二种情况是什么导致了错误,因为例如10/3这样的单个数字天没有前导零。

理想情况下,代码会将date分隔成单独的单元格,如:10 / 11,10 / 11,10 / 13和10 / 3,10 / 4,10 / 5。 然而,当单位数天存在时,它完全混乱并且不准确。

无可否认,我还有另外一个同事正在度假,现在正在休假,这就是为什么我有这样的麻烦理解这一点。 有什么我可以改变为单个数字天或我应该以不同的方式处理这个过程?

谢谢!

'separate column J by "/" and store in transpose area dim h as variant dim i as variant dim j as variant dim counter as variant dim stringcheck as variant dim strInput as variant dim strCurrent as variant strInput = Cells(j, 10) h = 0 For counter = 1 To Len(strInput) - 2 stringcheck = InStr(strInput, "/") Debug.Print j & stringcheck If stringcheck <> 0 Then If Mid(strInput, counter, 1) = "/" Then Cells(17, i + h) = strCurrent & Mid(strInput, counter, 3) counter = counter + 2 h = h + 1 strCurrent = vbNullString Else Cells(17, i + h) = Cells(j, 10) strCurrent = strCurrent & Mid(strInput, counter, 1) End If 'else just paste the value Else Cells(17, i) = strInput End If Next counter 

如果一个单元的混合date内的所有月份都可以合理地假定为相同,那么可以用它作为分隔符来分割混搭并重新组合。

 Function splitMashUp(str As String, _ Optional splitchr As String = "/", _ Optional delim As String = ", ") Dim i As Long, tmp As Variant tmp = Split(str, Left(str, InStr(1, str, splitchr))) For i = LBound(tmp) + 1 To UBound(tmp) tmp(i) = Left(str, InStr(1, str, splitchr)) & tmp(i) Next i splitMashUp = Mid(Join(tmp, delim), Len(delim) + 1) End Function 

在这里输入图像说明