Home > database >  Paste the value start from the range until the last row while using DO WHILE LOOP dates
Paste the value start from the range until the last row while using DO WHILE LOOP dates

Time:02-03

I have sheets with data that has 56 rows all and I'm using DO WHILE LOOP in dates by week. By using this Range("A" & Rows.count).End(xlUp).Offset(1, 0) this code it will start paste the value start from Range("A57") because A57 is the last available row. I want to paste start from A3 not in A57

This is the code.

    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")`

CodePudding user response:

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")
  • Related