-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnpivotTools.txt
541 lines (449 loc) · 22 KB
/
UnpivotTools.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
Option Explicit
Sub unpivot()
'Sheets("TEST").Range("A1:AAA200000").ClearContents
Dim sn As Variant
Dim colOrig As Variant
Dim colOriginalLength As Integer
Dim sk As Variant
Dim x As Variant
Dim y As Variant
Dim sp As Variant
Dim j As Variant
Dim m As Variant
Dim n As Variant
Dim RowLen As Long
Dim wsNew As Worksheet
Dim wsCalc As Worksheet
Dim i As Long
Dim colNum As Integer
Dim rng As Range
Dim xtraRange As Range
Dim NewBook As Workbook
Dim screenUpdateState As Variant
Dim statusBarState As Variant
Dim calcState As Variant
Dim eventsState As Variant
screenUpdateState = Application.ScreenUpdating
statusBarState = Application.DisplayStatusBar
calcState = Application.Calculation
eventsState = Application.EnableEvents
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
MsgBox "Excel will be unavailable for about a minute. Press OK when ready."
Set wsCalc = ActiveWorkbook.Worksheets("CALCULATIONS")
Call AddNew(NewBook)
Set wsNew = NewBook.Sheets("DATA")
'Year and Month, sets original size of block for all lengths
sn = wsCalc.Range("BH5:DE2000").Value
x = UBound(sn, 2)
y = UBound(sn, 2) - x
ReDim sp(1 To x * (UBound(sn) - 1), 1 To 4)
For j = 1 To UBound(sp)
m = (j - 1) Mod (UBound(sn) - 1) + 2
n = (j - 1) \ (UBound(sn) - 1) + y + 1
sp(j, 1) = Left(sn(1, n), 4) 'Does the year unpivot
sp(j, 2) = Left(sn(1, n), 4) & " / " & Right(sn(1, n), 2) 'Does the fiscal month unpivot
Next
wsNew.Cells(2, 1).Resize(UBound(sp), UBound(sp, 2)) = sp
RowLen = UBound(sp)
'ADD SOMETHING TO MAKE THESE COLUMNS GET PASSED A NAME AND DO WHAT THEY NEED TO DO FOR NAMING
'MAKE THESE AUTOMATICALLY MEASURE THE ARRAY SO DONT NEED TO PASS EXACT COLUMNS
'Proper formatting of columns
wsNew.Columns(1).NumberFormat = "@"
wsNew.Columns(4).NumberFormat = "@"
wsNew.Columns(5).NumberFormat = "@"
wsNew.Columns(3).NumberFormat = "@"
wsNew.Columns(15).NumberFormat = "@"
wsNew.Columns(17).NumberFormat = "@"
Call createSingleValueColumns(RowLen, 3, "COMP0001", wsNew) 'Dupes the company name
Call repeatColumns(wsCalc.Range("F6:F2000"), 4, RowLen, wsNew) 'Handles PFC
Call createSingleValueColumns(RowLen, 5, "5000", wsNew) 'Dup account number
Call repeatColumns(wsCalc.Range("J6:J2000"), 6, RowLen, wsNew) 'Customer Name
Call repeatColumns(wsCalc.Range("L6:L2000"), 7, RowLen, wsNew) 'Ship-To City
Call repeatColumnsWithConcat(wsCalc.Range("M6:M2000"), wsCalc.Range("N6:N2000"), 15, RowLen, wsNew) 'Product Num with Fill code
Call repeatColumns(wsCalc.Range("W6:W2000"), 16, RowLen, wsNew) 'Fill "code"
Call repeatColumns(wsCalc.Range("M6:M2000"), 17, RowLen, wsNew) 'Base Product Number
Call repeatColumns(wsCalc.Range("O6:O2000"), 20, RowLen, wsNew) 'UOM
Call transposeBlock(wsCalc.Range("ACF5:AEC2000"), 25, wsNew) 'Gross Sales
Call transposeBlock(wsCalc.Range("BIX5:BKU2000"), 28, wsNew) 'RM + Pkg Standard Cost
Call transposeBlock(wsCalc.Range("CCD5:CEA2000"), 31, wsNew) 'Conversion Costs at Standard
'Call transposeBlock(wsCalc.Range("ACF5:AEC2000"), 35, wsNew) Put these in later
'Call transposeBlock(wsCalc.Range("AGB5:AHY2000"), 38, wsNew) Put these in later
Call transposeBlock(wsCalc.Range("OT5:QQ2000"), 41, wsNew) 'volumes in UOM
Call transposeBlock(wsCalc.Range("QR5:SO2000"), 42, wsNew) 'volumes in Gallons
Call createSingleValueColumns(RowLen, 43, 1, wsNew) 'Exchange Rate Nonsense
Call createSingleValueColumns(RowLen, 44, 1, wsNew) 'Exchange Rate Nonsense
Call createSingleValueColumns(RowLen, 45, 1, wsNew) 'Exchange Rate Nonsense
Call createSingleValueColumns(RowLen, 46, 1, wsNew) 'Exchange Rate Nonsense
Call createSingleValueColumns(RowLen, 47, 1, wsNew) 'Exchange Rate Nonsense
Call createSingleValueColumns(RowLen, 48, 1, wsNew) 'Exchange Rate Nonsense
Call createSingleValueColumns(RowLen, 49, "Budget", wsNew) 'Straight Name as Budget for now -MAKE THIS AUTOMATIC IN FUTURE ADDITIONS
Call transposeBlock(wsCalc.Range("AVL5:AXI2000"), 50, wsNew) 'Pricing (Invoice Price Change Impact)
Call transposeBlock(wsCalc.Range("AXJ5:AZG2000"), 51, wsNew) 'Pricing (Rebate Change Impact)
Call transposeBlock(wsCalc.Range("AZH5:BBE2000"), 52, wsNew) 'Pricing (Mechanism Change Impact)
Call transposeBlock(wsCalc.Range("BDD5:BFA2000"), 53, wsNew) 'Pricing (Volume Impact)
Call transposeBlock(wsCalc.Range("BFB5:BGY2000"), 54, wsNew) 'Pricing (Mix Impact)
Call transposeBlock(wsCalc.Range("BGZ5:BIW2000"), 55, wsNew) 'Price Impact (Other)
Call transposeBlock(wsCalc.Range("ATN5:AVK2000"), 56, wsNew) 'TOTAL NET SALES $
Call transposeBlock(wsCalc.Range("BIX5:BKU2000"), 57, wsNew) 'RM + Pkg - Standard Cost
Call transposeBlock(wsCalc.Range("BKV5:BMS2000"), 58, wsNew) 'RM + Pkg - AVERAGE Standard Cost
Call transposeBlock(wsCalc.Range("BMT5:BOQ2000"), 59, wsNew) 'RM (Cost Change Impact)
Call transposeBlock(wsCalc.Range("BOR5:BQO2000"), 60, wsNew) 'RM (Volume Impact)
Call transposeBlock(wsCalc.Range("BQP5:BSM2000"), 61, wsNew) 'RM (Volume Mix Impact)
Call transposeBlock(wsCalc.Range("BSN5:BUK2000"), 62, wsNew) 'RM STD (OTHER Impact)
Call transposeBlock(wsCalc.Range("BUL5:BWI2000"), 63, wsNew) 'RM (COS RESERVE)
Call transposeBlock(wsCalc.Range("BWJ5:BYG2000"), 64, wsNew) 'PPV & RM Std Cost Change Allocation on Gallons
Call transposeBlock(wsCalc.Range("BYH5:CAE2000"), 65, wsNew) 'RM Costs - Other
Call transposeBlock(wsCalc.Range("CAF5:CCC2000"), 66, wsNew) 'Total Raw Material Costs
Call transposeBlock(wsCalc.Range("CCD5:CEA2000"), 67, wsNew) 'Conversion Costs - Standard Costs
Call transposeBlock(wsCalc.Range("CEB5:CFY2000"), 68, wsNew) 'Conversion Costs - AVERAGE Standard Cost
Call transposeBlock(wsCalc.Range("CFZ5:CHW2000"), 69, wsNew) 'CONV COST (Cost Change Impact)
Call transposeBlock(wsCalc.Range("CHX5:CJU2000"), 70, wsNew) 'CONV COST (Volume Impact)
Call transposeBlock(wsCalc.Range("CJV5:CLS2000"), 71, wsNew) 'CONV COST (Mix Impact)
Call transposeBlock(wsCalc.Range("CLT5:CNQ2000"), 72, wsNew) 'CONV COST (Other Impact)
Call transposeBlock(wsCalc.Range("CNR5:CPO2000"), 73, wsNew) 'Under(Over) Absorption & CC Std Cost Change Allocation on Gallons
Call transposeBlock(wsCalc.Range("CPP5:CRM2000"), 74, wsNew) 'Conversion Costs - Other
Call transposeBlock(wsCalc.Range("CRN5:CTK2000"), 75, wsNew) 'Converison Costs - Total
Call transposeBlock(wsCalc.Range("CTL5:CVI2000"), 76, wsNew) 'Warehousing Allocation on Gallons
Call transposeBlock(wsCalc.Range("CVJ5:CXG2000"), 77, wsNew) 'Research & Development
Call transposeBlock(wsCalc.Range("CXH5:CZE2000"), 78, wsNew) 'Freight OUT Allocation on Gallons
Call transposeBlock(wsCalc.Range("CZF5:DBC2000"), 79, wsNew) 'Other COGS
Call transposeBlock(wsCalc.Range("DBD5:DDA2000"), 80, wsNew) 'GROSS MARGIN $
Call transposeBlock(wsCalc.Range("DEZ5:DGW2000"), 81, wsNew) 'New/Lost Gallons
Call transposeBlock(wsCalc.Range("DGX5:DIU2000"), 82, wsNew) 'New/Lost Sales
Call transposeBlock(wsCalc.Range("AJX5:ALU2000"), 83, wsNew) 'Mechanism Dollars
Call transposeBlock(wsCalc.Range("ANT5:APQ2000"), 84, wsNew) 'Rebate Dollars
Call transposeBlock(wsCalc.Range("APR5:ARO2000"), 85, wsNew) 'Other Rebate Dollars
Call transposeBlock(wsCalc.Range("ARP5:ATM2000"), 86, wsNew) 'Other Net Sales
Call transposeBlock(wsCalc.Range("AAH5:ACE2000"), 87, wsNew) 'Final Prices
Call transposeBlock(wsCalc.Range("AGB5:AHY2000"), 88, wsNew) 'Returns
Call transposeBlock(wsCalc.Range("DIV5:DKS2000"), 89, wsNew) 'RM + Pkg - Actual Cost
Call transposeBlock(wsCalc.Range("DKT5:DMQ2000"), 90, wsNew) 'Conversion - Actual Cost
Call CreateTitles(wsNew)
Selection.SpecialCells(xlCellTypeBlanks).Value = 0
Call DeleteEndRows(wsNew)
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.Calculation = xlCalculationManual
Application.EnableEvents = True
End Sub
Sub unpivotForBatchProcessing()
Dim sn As Variant
Dim colOrig As Variant
Dim colOriginalLength As Integer
Dim sk As Variant
Dim x As Variant
Dim y As Variant
Dim sp As Variant
Dim j As Variant
Dim m As Variant
Dim n As Variant
Dim RowLen As Long
Dim wsNew As Worksheet
Dim wsCalc As Worksheet
Dim i As Long
Dim colNum As Integer
Dim rng As Range
Dim xtraRange As Range
Dim NewBook As Workbook
Dim screenUpdateState As Variant
Dim statusBarState As Variant
Dim calcState As Variant
Dim eventsState As Variant
screenUpdateState = Application.ScreenUpdating
statusBarState = Application.DisplayStatusBar
calcState = Application.Calculation
eventsState = Application.EnableEvents
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Set wsCalc = ActiveWorkbook.Worksheets("CALCULATIONS")
Call AddNew(NewBook)
Set wsNew = NewBook.Sheets("DATA")
'Year and Month, sets original size of block for all lengths
sn = wsCalc.Range("BH5:DE2000").Value
x = UBound(sn, 2)
y = UBound(sn, 2) - x
ReDim sp(1 To x * (UBound(sn) - 1), 1 To 4)
For j = 1 To UBound(sp)
m = (j - 1) Mod (UBound(sn) - 1) + 2
n = (j - 1) \ (UBound(sn) - 1) + y + 1
sp(j, 1) = Left(sn(1, n), 4) 'Does the year unpivot
sp(j, 2) = Left(sn(1, n), 4) & " / " & Right(sn(1, n), 2) 'Does the fiscal month unpivot
Next
wsNew.Cells(2, 1).Resize(UBound(sp), UBound(sp, 2)) = sp
RowLen = UBound(sp)
'ADD SOMETHING TO MAKE THESE COLUMNS GET PASSED A NAME AND DO WHAT THEY NEED TO DO FOR NAMING
'MAKE THESE AUTOMATICALLY MEASURE THE ARRAY SO DONT NEED TO PASS EXACT COLUMNS
'Proper formatting of columns
wsNew.Columns(1).NumberFormat = "@"
wsNew.Columns(4).NumberFormat = "@"
wsNew.Columns(5).NumberFormat = "@"
wsNew.Columns(3).NumberFormat = "@"
wsNew.Columns(15).NumberFormat = "@"
wsNew.Columns(17).NumberFormat = "@"
Call createSingleValueColumns(RowLen, 3, "COMP0001", wsNew) 'Dupes the company name
Call repeatColumns(wsCalc.Range("F6:F2000"), 4, RowLen, wsNew) 'Handles PFC
Call createSingleValueColumns(RowLen, 5, "5000", wsNew) 'Dup account number
Call repeatColumns(wsCalc.Range("J6:J2000"), 6, RowLen, wsNew) 'Customer Name
Call repeatColumns(wsCalc.Range("L6:L2000"), 7, RowLen, wsNew) 'Ship-To City
Call repeatColumnsWithConcat(wsCalc.Range("M6:M2000"), wsCalc.Range("N6:N2000"), 15, RowLen, wsNew) 'Product Num with Fill code
Call repeatColumns(wsCalc.Range("W6:W2000"), 16, RowLen, wsNew) 'Fill "code"
Call repeatColumns(wsCalc.Range("M6:M2000"), 17, RowLen, wsNew) 'Base Product Number
Call repeatColumns(wsCalc.Range("O6:O2000"), 20, RowLen, wsNew) 'UOM
Call transposeBlock(wsCalc.Range("ACF5:AEC2000"), 25, wsNew) 'Gross Sales
Call transposeBlock(wsCalc.Range("BIX5:BKU2000"), 28, wsNew) 'RM + Pkg Standard Cost
Call transposeBlock(wsCalc.Range("CCD5:CEA2000"), 31, wsNew) 'Conversion Costs at Standard
'Call transposeBlock(wsCalc.Range("ACF5:AEC2000"), 35, wsNew) Put these in later
'Call transposeBlock(wsCalc.Range("AGB5:AHY2000"), 38, wsNew) Put these in later
Call transposeBlock(wsCalc.Range("OT5:QQ2000"), 41, wsNew) 'volumes in UOM
Call transposeBlock(wsCalc.Range("QR5:SO2000"), 42, wsNew) 'volumes in Gallons
Call createSingleValueColumns(RowLen, 43, 1, wsNew) 'Exchange Rate Nonsense
Call createSingleValueColumns(RowLen, 44, 1, wsNew) 'Exchange Rate Nonsense
Call createSingleValueColumns(RowLen, 45, 1, wsNew) 'Exchange Rate Nonsense
Call createSingleValueColumns(RowLen, 46, 1, wsNew) 'Exchange Rate Nonsense
Call createSingleValueColumns(RowLen, 47, 1, wsNew) 'Exchange Rate Nonsense
Call createSingleValueColumns(RowLen, 48, 1, wsNew) 'Exchange Rate Nonsense
Call createSingleValueColumns(RowLen, 49, "Budget", wsNew) 'Straight Name as Budget for now -MAKE THIS AUTOMATIC IN FUTURE ADDITIONS
Call transposeBlock(wsCalc.Range("AVL5:AXI2000"), 50, wsNew) 'Pricing (Invoice Price Change Impact)
Call transposeBlock(wsCalc.Range("AXJ5:AZG2000"), 51, wsNew) 'Pricing (Rebate Change Impact)
Call transposeBlock(wsCalc.Range("AZH5:BBE2000"), 52, wsNew) 'Pricing (Mechanism Change Impact)
Call transposeBlock(wsCalc.Range("BDD5:BFA2000"), 53, wsNew) 'Pricing (Volume Impact)
Call transposeBlock(wsCalc.Range("BFB5:BGY2000"), 54, wsNew) 'Pricing (Mix Impact)
Call transposeBlock(wsCalc.Range("BGZ5:BIW2000"), 55, wsNew) 'Price Impact (Other)
Call transposeBlock(wsCalc.Range("ATN5:AVK2000"), 56, wsNew) 'TOTAL NET SALES $
Call transposeBlock(wsCalc.Range("BIX5:BKU2000"), 57, wsNew) 'RM + Pkg - Standard Cost
Call transposeBlock(wsCalc.Range("BKV5:BMS2000"), 58, wsNew) 'RM + Pkg - AVERAGE Standard Cost
Call transposeBlock(wsCalc.Range("BMT5:BOQ2000"), 59, wsNew) 'RM (Cost Change Impact)
Call transposeBlock(wsCalc.Range("BOR5:BQO2000"), 60, wsNew) 'RM (Volume Impact)
Call transposeBlock(wsCalc.Range("BQP5:BSM2000"), 61, wsNew) 'RM (Volume Mix Impact)
Call transposeBlock(wsCalc.Range("BSN5:BUK2000"), 62, wsNew) 'RM STD (OTHER Impact)
Call transposeBlock(wsCalc.Range("BUL5:BWI2000"), 63, wsNew) 'RM (COS RESERVE)
Call transposeBlock(wsCalc.Range("BWJ5:BYG2000"), 64, wsNew) 'PPV & RM Std Cost Change Allocation on Gallons
Call transposeBlock(wsCalc.Range("BYH5:CAE2000"), 65, wsNew) 'RM Costs - Other
Call transposeBlock(wsCalc.Range("CAF5:CCC2000"), 66, wsNew) 'Total Raw Material Costs
Call transposeBlock(wsCalc.Range("CCD5:CEA2000"), 67, wsNew) 'Conversion Costs - Standard Costs
Call transposeBlock(wsCalc.Range("CEB5:CFY2000"), 68, wsNew) 'Conversion Costs - AVERAGE Standard Cost
Call transposeBlock(wsCalc.Range("CFZ5:CHW2000"), 69, wsNew) 'CONV COST (Cost Change Impact)
Call transposeBlock(wsCalc.Range("CHX5:CJU2000"), 70, wsNew) 'CONV COST (Volume Impact)
Call transposeBlock(wsCalc.Range("CJV5:CLS2000"), 71, wsNew) 'CONV COST (Mix Impact)
Call transposeBlock(wsCalc.Range("CLT5:CNQ2000"), 72, wsNew) 'CONV COST (Other Impact)
Call transposeBlock(wsCalc.Range("CNR5:CPO2000"), 73, wsNew) 'Under(Over) Absorption & CC Std Cost Change Allocation on Gallons
Call transposeBlock(wsCalc.Range("CPP5:CRM2000"), 74, wsNew) 'Conversion Costs - Other
Call transposeBlock(wsCalc.Range("CRN5:CTK2000"), 75, wsNew) 'Converison Costs - Total
Call transposeBlock(wsCalc.Range("CTL5:CVI2000"), 76, wsNew) 'Warehousing Allocation on Gallons
Call transposeBlock(wsCalc.Range("CVJ5:CXG2000"), 77, wsNew) 'Research & Development
Call transposeBlock(wsCalc.Range("CXH5:CZE2000"), 78, wsNew) 'Freight OUT Allocation on Gallons
Call transposeBlock(wsCalc.Range("CZF5:DBC2000"), 79, wsNew) 'Other COGS
Call transposeBlock(wsCalc.Range("DBD5:DDA2000"), 80, wsNew) 'GROSS MARGIN $
Call transposeBlock(wsCalc.Range("DEZ5:DGW2000"), 81, wsNew) 'New/Lost Gallons
Call transposeBlock(wsCalc.Range("DGX5:DIU2000"), 82, wsNew) 'New/Lost Sales
Call transposeBlock(wsCalc.Range("AJX5:ALU2000"), 83, wsNew) 'Mechanism Dollars
Call transposeBlock(wsCalc.Range("ANT5:APQ2000"), 84, wsNew) 'Rebate Dollars
Call transposeBlock(wsCalc.Range("APR5:ARO2000"), 85, wsNew) 'Other Rebate Dollars
Call transposeBlock(wsCalc.Range("ARP5:ATM2000"), 86, wsNew) 'Other Net Sales
Call transposeBlock(wsCalc.Range("AAH5:ACE2000"), 87, wsNew) 'Final Prices
Call transposeBlock(wsCalc.Range("AGB5:AHY2000"), 88, wsNew) 'Returns
Call transposeBlock(wsCalc.Range("DIV5:DKS2000"), 89, wsNew) 'RM + Pkg - Actual Cost
Call transposeBlock(wsCalc.Range("DKT5:DMQ2000"), 90, wsNew) 'Conversion - Actual Cost
Call CreateTitles(wsNew)
Call DeleteEndRows(wsNew)
Selection.SpecialCells(xlCellTypeBlanks).Value = 0
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.Calculation = xlCalculationManual
Application.EnableEvents = True
End Sub
Sub repeatColumns(rng As Range, col As Integer, RowLen As Long, wsNew As Object)
Dim sk As Variant
Dim sn As Variant
Dim j As Variant
Dim colOrig As Variant
Dim colOriginalLength As Integer
colOrig = rng.Value
colOriginalLength = UBound(colOrig, 1) - LBound(colOrig, 1) + 1
ReDim sk(1 To RowLen, 1 To 1)
For j = 1 To UBound(sk)
sk(j, 1) = colOrig(((j - 1) Mod colOriginalLength) + 1, 1)
Next
wsNew.Cells(2, col).Resize(RowLen, 1) = sk
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.Calculation = xlCalculationManual
Application.EnableEvents = True
End Sub
Sub createSingleValueColumns(RowLen As Long, colNum As Integer, Val As Variant, wsNew As Object)
Dim i As Long
For i = 2 To (RowLen + 1)
wsNew.Cells(i, colNum) = Val
Next i
End Sub
Sub transposeBlock(rng As Range, colNum As Integer, wsNew As Object)
Dim sz As Variant
Dim sp As Variant
Dim x As Long
Dim y As Long
Dim j As Long
Dim m As Long
Dim n As Long
Dim rd As Range
sz = rng.Value
x = UBound(sz, 2)
y = UBound(sz, 2) - x
ReDim sp(1 To x * (UBound(sz) - 1), 1 To 1)
For j = 1 To UBound(sp)
m = (j - 1) Mod (UBound(sz) - 1) + 2
n = (j - 1) \ (UBound(sz) - 1) + y + 1
sp(j, 1) = sz(m, n) 'does the array block
Next
Set rd = wsNew.Cells(2, colNum).Resize(UBound(sp), 1)
rd = sp
End Sub
Sub CreateTitles(wsNew As Object)
wsNew.Cells(1, 1) = "Fiscal Year"
wsNew.Cells(1, 2) = "Fiscal Month"
wsNew.Cells(1, 3) = "Company Code"
wsNew.Cells(1, 4) = "Profit Center Code"
wsNew.Cells(1, 5) = "Account Category Code"
wsNew.Cells(1, 6) = "Customer Name"
wsNew.Cells(1, 7) = "Ship To City"
wsNew.Cells(1, 8) = "Ship To Customer GL Class"
wsNew.Cells(1, 9) = "Ship-To Customer Number"
wsNew.Cells(1, 10) = "Sales Invoice Number"
wsNew.Cells(1, 11) = "Invoice Actual Ship Date"
wsNew.Cells(1, 12) = "Invoiced Date"
wsNew.Cells(1, 13) = "Analytics Mfg Source"
wsNew.Cells(1, 14) = "Analytics Mfg Source Description"
wsNew.Cells(1, 15) = "Product Number"
wsNew.Cells(1, 16) = "Fill Code"
wsNew.Cells(1, 17) = "Base Product Number"
wsNew.Cells(1, 18) = "Product GL Class and Description"
wsNew.Cells(1, 19) = "Product Description"
wsNew.Cells(1, 20) = "Base UOM"
wsNew.Cells(1, 21) = "Conversion Factor to GAL"
wsNew.Cells(1, 22) = "Conversion Factor to LB"
wsNew.Cells(1, 23) = "Sales Class Description"
wsNew.Cells(1, 24) = "BPA"
wsNew.Cells(1, 25) = "Net Invoiced Amount at Doc"
wsNew.Cells(1, 26) = "Net Invoiced Amount at AFX"
wsNew.Cells(1, 27) = "Ext Total STD Cost at Document Rate"
wsNew.Cells(1, 28) = "Ext Raw Material STD Cost at Document Rate"
wsNew.Cells(1, 29) = "Ext Packaging STD Cost at Document Rate"
wsNew.Cells(1, 30) = "Ext Warehouse STD Cost at Document Rate"
wsNew.Cells(1, 31) = "Ext Fixed Conversion STD Cost at Document Rate"
wsNew.Cells(1, 32) = "Ext Variable Conversion STD Cost at Document Rate"
wsNew.Cells(1, 33) = "Ext COSR STD Cost at Document Rate"
wsNew.Cells(1, 34) = "Ext Total Actual Cost at Document Rate"
wsNew.Cells(1, 35) = "Ext Raw Material Actual Cost at Document Rate"
wsNew.Cells(1, 36) = "Ext Packaging Actual Cost at Document Rate"
wsNew.Cells(1, 37) = "Ext Warehouse Actual Cost at Document Rate"
wsNew.Cells(1, 38) = "Ext Fixed Conversion Actual Cost at Document Rate"
wsNew.Cells(1, 39) = "Ext Variable Conversion Actual Cost at Document Rate"
wsNew.Cells(1, 40) = "Ext COSR Actual Cost at Document Rate"
wsNew.Cells(1, 41) = "Net Quantity"
wsNew.Cells(1, 42) = "Net Quantity in GAL"
wsNew.Cells(1, 43) = "Average Rate"
wsNew.Cells(1, 44) = "Budget Rate"
wsNew.Cells(1, 45) = "Local Exchange Rate"
wsNew.Cells(1, 46) = "Corp Exchange Rate"
wsNew.Cells(1, 47) = "Local Currency Code"
wsNew.Cells(1, 48) = "Sales Class Description"
wsNew.Cells(1, 49) = "SOURCE"
wsNew.Cells(1, 50) = "Pricing-Invoice"
wsNew.Cells(1, 51) = "Pricing-Rebates"
wsNew.Cells(1, 52) = "Pricing-Mechanisms"
wsNew.Cells(1, 53) = "Volume Change"
wsNew.Cells(1, 54) = "Mix Change"
wsNew.Cells(1, 55) = "Other"
wsNew.Cells(1, 56) = "Total Net Sales"
wsNew.Cells(1, 57) = "RM + Pkg - Standard Cost"
wsNew.Cells(1, 58) = "RM + Pkg - AVERAGE Standard Cost"
wsNew.Cells(1, 59) = "RM (Cost Change Impact)"
wsNew.Cells(1, 60) = "RM (Volume Impact)"
wsNew.Cells(1, 61) = "RM (Mix Impact)"
wsNew.Cells(1, 62) = "RM STD (OTHER Impact)"
wsNew.Cells(1, 63) = "RM (COS RESERVE)"
wsNew.Cells(1, 64) = "PPV & RM Std Cost Change Allocation on Gallons"
wsNew.Cells(1, 65) = "RM Costs - Other"
wsNew.Cells(1, 66) = "Total Raw Material Costs"
wsNew.Cells(1, 67) = "Conversion Costs - Standard Costs"
wsNew.Cells(1, 68) = "Conversion Costs - AVERAGE Standard Cost"
wsNew.Cells(1, 69) = "CONV COST (Cost Change Impact)"
wsNew.Cells(1, 70) = "CONV COST (Volume Impact)"
wsNew.Cells(1, 71) = "CONV COST (Mix Impact)"
wsNew.Cells(1, 72) = "CONV COST (Other Impact)"
wsNew.Cells(1, 73) = "Under(Over) Absorption & CC Std Cost Change Allocation on Gallons"
wsNew.Cells(1, 74) = "Conversion Costs - Other"
wsNew.Cells(1, 75) = "Converison Costs - Total"
wsNew.Cells(1, 76) = "Warehousing Allocation on Gallons"
wsNew.Cells(1, 77) = "Research & Development"
wsNew.Cells(1, 78) = "Freight OUT Allocation on Gallons"
wsNew.Cells(1, 79) = "Other COGS"
wsNew.Cells(1, 80) = "Gross Margin"
wsNew.Cells(1, 81) = "New/Lost Gallons"
wsNew.Cells(1, 82) = "New/Lost Sales"
wsNew.Cells(1, 83) = "Mechanism Dollars"
wsNew.Cells(1, 84) = "Rebate Dollars"
wsNew.Cells(1, 85) = "Other Rebate Dollars"
wsNew.Cells(1, 86) = "Other Net Sales"
wsNew.Cells(1, 87) = "Final Prices"
wsNew.Cells(1, 88) = "Returns (alloc on gallons)"
wsNew.Cells(1, 89) = "RM + Pkg - Actual Cost"
wsNew.Cells(1, 90) = "Conversion - Actual Cost"
End Sub
Sub repeatColumnsWithConcat(rng As Range, xtraRange As Range, col As Integer, RowLen As Long, wsNew As Object)
Dim sk As Variant
Dim sn As Variant
Dim j As Variant
Dim colOrig As Variant
Dim colOriginalLength As Integer
Dim colConcat As Variant
colOrig = rng.Value
colConcat = xtraRange.Value
For j = 1 To UBound(colOrig)
colOrig(j, 1) = colOrig(j, 1) & "." & colConcat(j, 1)
Next
colOriginalLength = UBound(colOrig, 1) - LBound(colOrig, 1) + 1
ReDim sk(1 To RowLen, 1 To 1)
For j = 1 To UBound(sk)
sk(j, 1) = colOrig(((j - 1) Mod colOriginalLength) + 1, 1)
Next
wsNew.Cells(2, col).Resize(RowLen, 1) = sk
End Sub
Sub DeleteEndRows(wsNew As Object)
With Range("F2:F200000")
.AutoFilter _
Field:=1, _
Criteria1:=0
.SpecialCells(12).EntireRow.Delete
End With
ActiveSheet.AutoFilterMode = False
End Sub
Sub AddNew(NewBook As Object)
'Dim NewBook As Workbook
Dim newPath As Variant
Dim SegName As Variant
SegName = ThisWorkbook.Sheets("Settings").Range("D29").Value
newPath = ActiveWorkbook.Path & "\" & SegName
Application.DisplayAlerts = False
Set NewBook = Workbooks.Add
With NewBook
.Title = "Calculations Output"
.Subject = "Sales"
.SaveAs Filename:=newPath
.Worksheets.Add().Name = "DATA"
End With
Application.DisplayAlerts = True
End Sub
Sub PathTest()
Dim newPath As Variant
Dim SegName As Variant
SegName = ThisWorkbook.Sheets("Settings").Range("D29").Value
newPath = ActiveWorkbook.Path & "\" & SegName
MsgBox (newPath)
End Sub