Avatar of agwalsh
agwalsh
 asked on

Copy and paste a set of entries at the bottom of a table but add 7 days to the previous entry for that data set..

I've asked this before but when the user added more categories - it stopped working so here I am again. In the attached file I have marked a number of entries in yellow at the bottom. Essentially I need a macro that will copy and paste that data set underneath but which will add 7 days onto the previous entry e.g. when it is completed the dates will be for 25/4/2021 and the year column and week number will reflect that.  There's a button on there already. Thank you :-)Data_update.xlsm
Microsoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Martin Liss

8/22/2022 - Mon
Rob Henson

Hi Anne,

The button isn't working on the sample file because it is linking to a macro in a separate file:
'C:\Users\Anne\AppData\Local\Microsoft\Windows\INetCache\Content.Outlook\Q2KBLU2G\Caoimhe_Sheridan_AnneWalsh_Excel_updated.xlsm'!FillDownValues

This could be because of it being uploaded to EE and downloaded again but it looks like it has been emailed.

Can you upload a file with the macro in it so we can check if it needs amending?
agwalsh

ASKER
yes, that would help wouldn't it...here is the original code....
Sub FillDownValues()
   
    Range("Table3[#Headers]").Select
    ColCount = Range("Table3[#Headers]").Count - 2
    HdrRow = Range("Table3[#Headers]").Row
    LastRow = Selection.End(xlDown).Row
   
    For r = 1 To 26
        For c = 1 To ColCount
            Cells(LastRow + r, c).Value = Cells(LastRow + r - 26, c).Value
            If Cells(HdrRow, c) = "Week Date" Then Cells(LastRow + r, c).Value = Cells(LastRow + r, c).Value + 7
        Next c
    Next r
    Selection.End(xlDown).Select
End Sub


ASKER CERTIFIED SOLUTION
Rob Henson

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Martin Liss

Could it be because you didn't define your variables?

Sub FillDownValues()
   Dim ColCount As Long
   Dim HdrRow As Long
   Dim LastRow As Long
   Dim r As Long
   Dim c As Long
   
    Range("Table3[#Headers]").Select
    ColCount = Range("Table3[#Headers]").Count - 2
    HdrRow = Range("Table3[#Headers]").Row
    LastRow = Selection.End(xlDown).Row
   
    For r = 1 To 26
        For c = 1 To ColCount
            Cells(LastRow + r, c).Value = Cells(LastRow + r - 26, c).Value
            If Cells(HdrRow, c) = "Week Date" Then Cells(LastRow + r, c).Value = Cells(LastRow + r, c).Value + 7
        Next c
    Next r
    Selection.End(xlDown).Select
End Sub

Open in new window


Is the macro in a code module like Module1?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23