Excel VBA: Copy and paste down cycle


I have an example spreadsheet that illustrates what I am trying to do.  I am looking for a way to take my date column and copy the first the record all the way down till it reaches a new date. Then it will take the new date and copy paste down..  This is a cycle that I would like it to repeat till End is found.

This will save a lot of manual work for us as we are compiling monthly data from various spreadsheets.

I have attached a spreadsheet for a better understanding.

Thank you SO much!
Maliki HassaniAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saurabh Singh TeotiaCommented:
Quick question..How do you determine the last row will it say end right now as shown in a column or how will it show??

Saqib Husain, SyedEngineerCommented:
Select the column A data range
press F5
Click on special
Select blanks
Click OK
type   =
from the keyboard move the cursor one cell up
press ctrl-enter
Saurabh Singh TeotiaCommented:
You can use the following code which will do what you are looking for..

Sub ap_formula()

    Dim rng As Range, lrow As Long
    Dim r As Range

    lrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
    Set rng = Range("A1:A" & lrow)

    Set r = rng.SpecialCells(xlCellTypeBlanks)

    r.FormulaR1C1 = "=R[-1]C"
    rng.Value = rng.Value

End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Maliki HassaniAuthor Commented:
Thank you!  Learned something new!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.