所以,我有一个代码正在打印“ mon-sun”的日子。每个单元格一天。这就是我想要的。但是目前,它是从K开始到Q结束,我希望它从正确的单元格中的开始日期开始。
因此,如果开始日期为2019-07-03,则为星期三。它应以“ M”而不是“ K”列开头。另外,在星期日停止。因此,如果开始日期和结束日期超过一周,则应该在星期日之后自动停止。
Dim FirstDate As Date
Dim LastDate As Date
Dim NextDate As Date
Dim DateOffset As Range
Dim DateIter As Date
FirstDate = Source.Range("J" & cell.Row).Value
LastDate = Source.Range("K" & cell.Row).Value
Set DateOffset = Target.Range("K" & LastRow + 1)
For DateIter = FirstDate To LastDate
DateOffset.Value = DateIter
Set DateOffset = DateOffset.Offset(0, 1)
Next DateIter
End With
End If
Next cell
编辑:
尝试此方法,但有时却不起作用。
FirstDate = Source.Range("J" & cell.Row).Value
LastDate = Source.Range("K" & cell.Row).Value
Set DateOffset = Target.Range("K" & LastRow + 1)
For DateIter = FirstDate To LastDate
' DateOffset.Value = DateIter
' Set DateOffset = DateOffset.Offset(0, 1)
If Weekday(DateIter, vbMonday) = 2 Then
Call anmalan_demo.Details(.Range("K" & LastRow + 1), "Må")
End If
If Weekday(DateIter, vbTuesday) = 3 Then
Call anmalan_demo.Details(.Range("L" & LastRow + 1), "Ti")
End If
If Weekday(DateIter, vbWednesday) = 4 Then
Call anmalan_demo.Details(.Range("M" & LastRow + 1), "On")
End If
If Weekday(DateIter, vbThursday) = 5 Then
Call anmalan_demo.Details(.Range("N" & LastRow + 1), "Tor")
End If
If Weekday(DateIter, vbFriday) = 6 Then
Call anmalan_demo.Details(.Range("O" & LastRow + 1), "Fre")
End If
If Weekday(DateIter, vbSaturday) = 7 Then
Call anmalan_demo.Details(.Range("P" & LastRow + 1), "Lö")
End If
If Weekday(DateIter, vbSunday) = 1 Then
Call anmalan_demo.Details(.Range("Q" & LastRow + 1), "Sö")
End If
Next DateIter
End With
End If
Next cell