【发布时间】:2016-09-09 18:12:49
【问题描述】:
我想比较日期以找到重叠的日期。
我创建的第一个函数检查完全重叠、部分重叠或无重叠。
这是第二个功能。它将用于扩展部分重叠过程,比较实际上重叠的内容,并提供重叠范围之间的日期序列,或创建带有短划线的第一个日期和重叠的最后一个日期。
到目前为止我的代码:
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
【问题讨论】:
-
只有年份重叠还是日期重叠才需要这个?
-
仅限年份,从技术上讲,所有使用的年份都是严格的数字。我最近发现我无法将 1900 年之前的任何事物作为年份进行比较,因此我只是将所有内容都转换为数字进行比较。所以对于这个例子,我应该得到数字 72 作为我的差异,并将其用作我的差异 for 循环。对于每次迭代,我想将 1 添加到 SD2。
标签: excel vba loops concatenation