我想比較日期以找到重疊的日期。通過循環值連接每個放入一個單元格
我創建的第一個函數檢查完整重疊,部分重疊或不重疊。
這是第二個功能。它將用於擴展部分重疊過程,比較實際重疊的內容,並提供重疊範圍之間的日期序列,或者創建第一個日期與短劃線和最後日期重疊的日期。
代碼我到目前爲止有:
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。 –