我想比较日期以找到重叠的日期。通过循环值连接每个放入一个单元格
我创建的第一个函数检查完整重叠,部分重叠或不重叠。
这是第二个功能。它将用于扩展部分重叠过程,比较实际重叠的内容,并提供重叠范围之间的日期序列,或者创建第一个日期与短划线和最后日期重叠的日期。
代码我到目前为止有:
Public Function partialdates(SD1 As Integer, ED1 As Integer, SD2 As Integer, ED2 As Integer) As String
'This function will be expanded, but the first If statement takes 1 case such that the first set of dates overlaps, but not beginning with the start date: SD1 = 1885 ED1 = 1969, SD2 = 1897 ED2 = 1972
Dim i As Integer
Dim years As Integer
Dim difference As Integer
If SD1 < SD2 And SD1 <= ED2 And ED1 <= ED2 And ED1 >= SD2 Then
difference = ED1 - SD2
For i = 1 To difference
' I need help with this, to create a sequence of years that will be what are
' overlapped, such as 1897, 1898, 1899...etc
years = years & ", " + 1
Next
partialdates = years
End If
End Function
你需要这个只用于多年重叠或日期重叠? – Karpak
只有多年,技术上所有使用的年份都是严格的数字。最近我发现1900年之前我无法比较任何东西,所以我只是将所有东西都转换成数字进行比较。因此,对于这个例子,我应该得到数字72为我的差异,并使用它作为我的差异循环。对于每次迭代,我想将1添加到SD2。 –