Code needed to shift data a given number columns to the right

richanor

Active Member
Joined
Apr 8, 2006
Messages
291
Hi all

I am trying to work out what the impact of the Covid-19 virus will have on our work schedules and wondered if somebody could help me with something:

I have a worksheet (called Chart), and in cell B1 I have the number of weeks expected delay (currently set to 3). In cells B3:BB3 I have the week numbers 1-52, and 52+. Under each week number (B4:BB4) I have the number of events expected to be completed in that week.

What I would like to do, is on row 5 (B5:BB5) to shift every number to the right a number of columns, according to the value given in call B1. So for example, if I currently have 6 projects due to finish in week 11 - I will have the number 6 in cell L4. On row 5, I would want this to be shifted along three rows to the right and so the number 6 would appear in cell O5 (indicating that they are now expected to be completed in week 14).

Here is the difficult bit: when it comes to the end of the range (BB3 - which represents 52+, or more than a year) I don't want the values just to be pushed along, I want them to be added up and just appear in cell BB5 as a total.

I have no idea if this is well enough explained to get a response, or even possible - but if anyone can help I'd really appreciate it.

Thanks

Rich
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Welcome to the MrExcel board!

Do you really need code?
Would formulas like these do? They could be added by code if necessary?
Is this what you mean?
Formula in B5 copied across to BA5 and BB5 is a separate formula

20 03 18.xlsm
BCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABB
13
2
31234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515252+
4363364394966997276564432682995937769719111494773456225
5   363364394966997276564432682995937769719111494773438
Move values
Cell Formulas
RangeFormula
B5:BA5B5=IF(B3>$B1,INDEX($B4:$BB4,COLUMNS($B5:B5)-$B1),"")
BB5BB5=SUM(B4:BB4)-SUM(B5:BA5)
 
Upvote 0
Absolute genius Peter - formulas are even better, it's just that my peanut sized brain couldn't work out how to possible achieve this with formulas (mainly the supping up bit at the end!

Could I ask one further favour. Now that I have put it in, I can see that I want it to appear sligtly differently:

as all the data is shifted along by the number of columns in B1, thecolumns to the left of the first data point all read '0', whereas I actually want these all to appear as the same as the first data point. So for example in your sheet above, cells B5:D5 are empty, but it would be more useful to me if they could appear the same as the first datapoint (E3)?

If not, don't worry - I thank you son much for your help

Rich
 
Upvote 0
whereas I actually want these all to appear as the same as the first data point. So for example in your sheet above, cells B5:D5 are empty, but it would be more useful to me if they could appear the same as the first datapoint (E3)
Like this?

20 03 18.xlsm
BCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABB
13
2
31234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515252+
4363364394966997276564432682995937769719111494773456225
5333363364394966997276564432682995937769719111494773438
Move values
Cell Formulas
RangeFormula
B5:BA5B5=IF(B3>$B1,INDEX($B4:$BB4,B3-$B1),$B4)
BB5BB5=SUM(B4:BB4)-SUM(B5:BA5)+B5*B1
 
Upvote 0
Hi, at the risk of asking for too much - I wonder if anybody could provide some further help with this project? The part above is working perfectly, but I am trying to add something else:

I now have a sheet which is able to work out the knock on / delays that the shutdown will cause. I have copied the results from B5:BB5 to B7:BB7 and so in cells B7:BB7 I have the number of projects outstanding for each week (1-52 and 52+). In cell BC7 I have the capacity available to complete, and I want to be able to deduct the capacity from the outstanding work, starting from week 52+ and working back.

So, if you look at the sheet Peter has posted above, in BB5 you can see I have 38 jobs at 52 weeks +, in BA5 I have 4 jobs, AZ5 I have 3 jobs and so on. I have my capacity in BC5, which lets assume is 53. What I would like to do is to start at BB7 and work backwards reducing the number of jobs until I reach my capacity. So in this example, my capacity is 53; so BB7 would become 0, BA7 would become 0, AZ7 would become 0, AY7 would become 0, and AX7 would become 6 (thus I have deducted 53 - my capacity) from the outstanding jobs, starting at the oldest and working back.

Again, I have no idea if this is achievable, and so no problem if nobody can help.

Cheers

Rich
 
Upvote 0
Like this?
I've hidden some columns to reduce the size of the screen shot.

richanor 2020-03-20 1.xlsm
BCDEFGHIJKLMNARASATAUAVAWAXAYAZBABBBC
13
2
3123456789101112134344454647484950515252+
43633643949669494773456225
5333363364394911149477343853
6
7333363364394911149460000
Move values (2)
Cell Formulas
RangeFormula
B5:N5,AR5:BA5B5=IF(B3>$B1,INDEX($B4:$BB4,B3-$B1),$B4)
BB5BB5=SUM(B4:BB4)-SUM(B5:BA5)+B5*B1
B7:N7,AR7:BB7B7=MIN(MAX(SUM(B5:$BB5)-$BC5,0),B5)
 
Upvote 0
Wow - that's brilliant. Thank you so much Peter - you have been so generous with your time, and it is very much appreciated.

Rich
 
Upvote 0
You're welcome. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,050
Members
449,206
Latest member
Healthydogs

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