Get all weeknums from 2 input dates and put them in an array?

前端 未结 2 1886
后悔当初
后悔当初 2021-01-23 07:46

Since I asked a wrong question in the last post, but still improved a lot (I already created a Planning table in Excel, if someone want it I will be happy to share), here is wha

2条回答
  •  清酒与你
    2021-01-23 08:20

    Using Application.WeekNum will be much more simple:

    Option Explicit
    Sub Test()
    
        Dim StartDate As Date, EndDate As Date
    
        With ThisWorkbook.Sheets("Foglio1") 'remember to fully qualify your ranges, including the workbook
            StartDate = .Range("B2")
            EndDate = .Range("B3")
        End With
    
        Dim StartWeek As Long, EndWeek As Long
        StartWeek = Application.WeekNum(StartDate, 2)
        EndWeek = Application.WeekNum(EndDate, 2)
    
        Dim arr
        Dim i As Long
        ReDim arr(StartWeek To EndWeek)
        For i = StartWeek To EndWeek
            arr(i) = i
        Next
    
    End Sub
    

提交回复
热议问题