excel 使用DO WHILE LOOP日期时,粘贴从范围开始到最后一行的值

6ss1mwsb  于 2023-02-05  发布在  其他
关注(0)|答案(1)|浏览(115)

我有一个工作表,其中的数据有56行,我正在使用DO WHILE LOOP在日期按周。通过使用这个Range("A" & Rows.count).End(xlUp).Offset(1, 0)这个代码,它将开始粘贴的值开始从范围("A57"),因为A57是最后一个可用的行。我想粘贴开始从A3,而不是在A57
这是密码。

Dim d As Date
    d = DateValue("31-dec-22")
    Dim LastDate As Date
    Dim StartDate As Date

    Do
     k = k + 7
     LastDate = DateAdd("d", k, d)
     StartDate = LastDate - 6
     Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = StartDate & " - " & LastDate
    Loop While LastDate <= CDate("1-jan-24")`
vshtjzan

vshtjzan1#

Dim d As Date
d = DateValue("31-dec-22")
Dim LastDate As Date
Dim StartDate As Date
Dim i As Integer
i = 0

Do
 k = k + 7
 LastDate = DateAdd("d", k, d)
 StartDate = LastDate - 6
 Range("A3").Offset(i, 0) = StartDate & " - " & LastDate
 i = i + 1
Loop While LastDate <= CDate("1-jan-24")

相关问题