VBA to copy a column to another column with the same date at the top

armchairandy

Board Regular
Joined
Mar 27, 2012
Messages
53
Hi

I have an input column with the date of input at the top and number values on each row of that column (30 no.). I then have a table of weekly dates horizontally in another section of the worksheet. What I need is to copy the data from the input column and paste the values into the corresponding date column in the historical table. Sort of creating a historical record of the values each week. After each week's input the data is copied to the corresponding date column in the historical table - they are both in the same workbook, but could be in separate workbooks in the future.


Input table

Col A
Heading:"Category"
Col B Heading "Input Date"
First Category in A3, the A4 and so on
The input Date is in B2
The value for the first category is in Col B3 against Category 1
Against each category there would be a numerical value under Column B

Historical Data Table

Columns AA2-to AZ2
Weekly dates

Under each corresponding date in the historical table would be that weeks values

Input tableHistorical Table
24/05/19 03/05/1910/05/1917/05/1924/05/19
Category 11Category 11 1
Category 21Category 24 21
Category 31Category 3 191
Category 4 Category 4647
Category 54Category 53 4
Category 6 Category 6463
Category 75Category 71355
Category 84Category 87414
Category 92Category 901 2
Category 103Category 100713
Category 11 Category 11401
Category 121Category 121011
Category 131Category 13 4 1
Category 142Category 14 1 2
Category 159Category 15 9

<colgroup><col><col><col span="2"><col><col span="2"><col span="2"></colgroup><tbody>
</tbody>


The obvious solution would be to copy & paste by hand, but I would have up to 30 different input columns each week & a similar task will be carried out by many other people, so I need the procedure to be without effort. Any help would be appreciated. Hope this makes sense.

Andrew
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
try
Code:
Sub Macro1()
    Range("B2:B17").Copy
    WkOffset = (Range("B2").Value - Range("D2").Value) \ 7
    Range("D2").Offset(0, WkOffset).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End Sub
 
Upvote 0
Repush

Many thanks for your help in this, sorry I didn't reply earlier, I was called away & had to put this on ice.

Regards

Andrew
 
Upvote 0

Forum statistics

Threads
1,213,561
Messages
6,114,316
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top