Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading