VBA Loop for each to build forecast

natekris8183

Board Regular
Joined
Mar 12, 2013
Messages
156
I have a data set that includes Column1 (Dates, week-to-week starting on Mondays), Column2 (product by SKU), Columns3 (product status, active... this will eventually be left out as soon as I finish the VBA to permit a list to be built allowing only active products to be selected in the data validation drop down), Column4 (Source: legacy or dealer). The SKUs are unique to the products obviously. I need to create a list range of data set to input into the Worksheet Function Trend based upon dates prior to the current date in the table range (RawSalesDataTbl[@Week]). This will provide a running trend to juxtapose against our proposed forecast. The complication is the data set is not linear thus I cannot simple name a range of "y" values and "x" values. The easy one is naming the proposed "X" value as it will be the next week value, again determined at RawSalesDataTbl[@Week].
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Unfortunately my profile in the Forum does not permit me to upload files. I'd be happy to furnish a sample copy if anyone would be willing to provide an email. It's only a test data set with fictitious SKU names. The layout is the same as the live raw data set. If someone knows how I can request changes to my posting permissions I would happily post.
 
Last edited:
Upvote 0
I did attempt the following two variations in hopes of creating an array. The complication is that the known x's are carried in but the False values generate null values as "0" and thus if the occurrences of the x's are 27 for SKU1 but there are 330 SKUs, the other 329 non-SKU1 values generate a "0" value there increasing the instances of X and incorrectly TREND the new X value.

Code:
=TREND(([SKU]=[@SKU])*[Actual],([SKU]=[@SKU])*([Week]<[@Week])*[Week],[@Week])

The other was the same with an IF statement array matching the SKU column to the current SKU value at that row and the same thing for the Y values of the known weeks based on the same array IF statement.
 
Upvote 0
You will need to download mrexcelhtml or excel genie. With one of these, you will be able to post an example worksheet.
 
Upvote 0
If you go to the main page of this site, click on excel questions, the very top post says recommended add-ins. Click on this and under recommended add-ins look for mrexcelhtml or excel genie.
 
Upvote 0
I only took just a few sample lines. There are over 17,000 so this is a segment of fabricated data as a sample.


Excel 2012
ABCDEFG
1WeekSKUSKU StatusSourceActualTrendForecast
21/12/15SKU10ActiveDealer10
31/19/15SKU10ActiveDealer8
42/2/15SKU10ActiveDealer7
52/16/15SKU10ActiveDealer7
63/2/15SKU10ActiveDealer5
73/23/15SKU10ActiveTCC1
84/6/15SKU10ActiveDealer3
94/13/15SKU10ActiveTCC1
104/27/15SKU10ActiveDealer10
116/1/15SKU10ActiveDealer3
126/22/15SKU10ActiveDealer6
136/22/15SKU10ActiveTCC1
146/29/15SKU10ActiveTCC3
157/6/15SKU10ActiveDealer21
168/3/15SKU10ActiveDealer11
178/10/15SKU10ActiveDealer5
188/17/15SKU10ActiveDealer5
198/31/15SKU10ActiveDealer10
208/31/15SKU100ActiveTCC050
218/31/15SKU101ActiveTCC057
228/31/15SKU102ActiveTCC034
238/31/15SKU103ActiveTCC049
248/31/15SKU104ActiveTCC0277
258/31/15SKU105ActiveTCC0172
268/31/15SKU106ActiveTCC0170
278/31/15SKU107ActiveTCC0175
288/31/15SKU108ActiveTCC0520
298/31/15SKU109ActiveTCC03
309/7/15SKU100ActiveTCC058
319/7/15SKU101ActiveTCC066
329/7/15SKU102ActiveTCC040
339/7/15SKU103ActiveTCC057
349/7/15SKU104ActiveTCC0323
359/7/15SKU105ActiveTCC0200
369/7/15SKU106ActiveTCC0198
379/7/15SKU107ActiveTCC0204
389/7/15SKU108ActiveTCC0607
399/7/15SKU109ActiveTCC04
409/14/15SKU100ActiveTCC058
419/14/15SKU101ActiveTCC066
429/14/15SKU102ActiveTCC040
439/14/15SKU103ActiveTCC057
449/14/15SKU104ActiveTCC0323
459/14/15SKU105ActiveTCC0200
469/14/15SKU106ActiveTCC0198
479/14/15SKU107ActiveTCC0204
489/14/15SKU108ActiveTCC0607
499/14/15SKU109ActiveTCC04
509/21/15SKU10ActiveDealer22
519/21/15SKU100ActiveDealer325
529/21/15SKU101ActiveDealer495
539/21/15SKU102ActiveDealer458
549/21/15SKU103ActiveDealer517
559/21/15SKU104ActiveDealer868
569/21/15SKU105ActiveDealer728
579/21/15SKU106ActiveDealer701
589/21/15SKU107ActiveDealer759
599/21/15SKU108ActiveDealer2078
609/21/15SKU109ActiveDealer13
619/21/15SKU10ActiveTCC20
629/21/15SKU100ActiveTCC17958
639/21/15SKU101ActiveTCC21366
649/21/15SKU102ActiveTCC12240
659/21/15SKU103ActiveTCC17357
669/21/15SKU104ActiveTCC1016323
679/21/15SKU105ActiveTCC619200
689/21/15SKU106ActiveTCC654198
699/21/15SKU107ActiveTCC636204
709/21/15SKU108ActiveTCC1792607
719/21/15SKU109ActiveTCC124
729/28/15SKU100ActiveDealer28
739/28/15SKU101ActiveDealer55
749/28/15SKU102ActiveDealer118
759/28/15SKU103ActiveDealer54
769/28/15SKU104ActiveDealer133
779/28/15SKU105ActiveDealer55
789/28/15SKU106ActiveDealer120
799/28/15SKU107ActiveDealer45
809/28/15SKU108ActiveDealer462
819/28/15SKU109ActiveDealer14
829/28/15SKU100ActiveTCC15759
839/28/15SKU101ActiveTCC13567
849/28/15SKU102ActiveTCC14641
859/28/15SKU103ActiveTCC13158
869/28/15SKU104ActiveTCC546330
879/28/15SKU105ActiveTCC725205
889/28/15SKU106ActiveTCC271202
899/28/15SKU107ActiveTCC729208
909/28/15SKU108ActiveTCC2082620
919/28/15SKU109ActiveTCC234
9210/5/15SKU10ActiveDealer10
9310/5/15SKU100ActiveDealer65
9410/5/15SKU101ActiveDealer111
9510/5/15SKU102ActiveDealer32
9610/5/15SKU103ActiveDealer79
9710/5/15SKU104ActiveDealer562
9810/5/15SKU105ActiveDealer99
9910/5/15SKU106ActiveDealer17
Raw Data
 
Last edited:
Upvote 0
Would your boss allow you to make an example sheet to bring home, to use on your personal computer?
 
Upvote 0
I was able to clip it out. The attached shows the sample. The aim is to get the trend of the associated SKU from the current row based on the date as the proposed "X" value with dates prior to that being the known "X" values and the values for "Y" would be the data in the Actual column associated by those dates less than the data associated with the current row. Hence why my previous function looked to build the array based on those values [Week]<[@Week]. The problem is that all False values generate a "0" in the array there by counting the "0".
 
Upvote 0

Forum statistics

Threads
1,214,858
Messages
6,121,960
Members
449,057
Latest member
FreeCricketId

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