-
Notifications
You must be signed in to change notification settings - Fork 0
/
Label Maker last working version.asa
2421 lines (1780 loc) · 96.7 KB
/
Label Maker last working version.asa
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
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Option Base 1
'NEw 2016 unqiue items function
Function UniqueItems(ArrayIn, Optional Count As Variant) As Variant
' Accepts an array or range as input
' If Count = True or is missing, the function returns the number of unique elements
' If Count = False, the function returns a variant array of unique elements
Dim Unique() As Variant ' array that holds the unique items
Dim Element As Variant
Dim i As Integer
Dim FoundMatch As Boolean
' If 2nd argument is missing, assign default value
If IsMissing(Count) Then Count = True
' Counter for number of unique elements
NumUnique = 0
' Loop thru the input array
For Each Element In ArrayIn
FoundMatch = False
' Has item been added yet?
For i = 1 To NumUnique
If Element = Unique(i) Then
FoundMatch = True
Exit For '(exit loop)
End If
Next i
AddItem:
' If not in list, add the item to unique list
If Not FoundMatch And Not IsEmpty(Element) Then
NumUnique = NumUnique + 1
ReDim Preserve Unique(NumUnique)
Unique(NumUnique) = Element
End If
Next Element
' Assign a value to the function
If Count Then UniqueItems = NumUnique Else UniqueItems = Unique
End Function
'WHAT TO DO WHEN SHIFTING COLUMNS: Last noted Feb 2016
' Update sunZero wedZero formulas in CODE column B
' Ctrl F all Hard Code text and review carefully
Function colBasedOnTitle(ws As String, sTitle As String) As Integer ' Added Jan 17th to extract the col of any header! SO SMART MAN
Dim cell As Range
Dim sTemp, sCell As String
Dim i As Integer
i = 1
Do While CStr(Worksheets(ws).Cells(1, i).Value) <> vbNullString Or i < 170 'check at least 170 columns, when oever 170 and there is a blank cell, call the search off
If CStr(Worksheets(ws).Cells(1, i).Value) = sTitle Then
colBasedOnTitle = i
sTemp = "match found"
End If
i = i + 1
Loop
If sTemp <> "match found" Then
MsgBox ("The [ " & sTitle & " ] column in the sheet [ " & ws & " ] could not be located, please do not change column titles. Please change title back or contact Akitasoft.com")
End If
End Function
Function oStart(left As String) As Integer ' Added extract the col of the start of the order field by inputing the name of the field to the left, "temp notes"
oStart = colBasedOnTitle("ORDERS", left) + 1
End Function
Function oEnd(right As String) As Integer ' Added extract the col of the end of the order field by inputing the name of the filed to the right, "TOTAL"
oEnd = colBasedOnTitle("ORDERS", right) - 1
End Function
Function showOnlyNames(rng As Range) As Variant ' Added Jan 17th to extract the name from any range of cells. Just used for data cleaning
Dim cell As Range
Dim sTemp, sCell As String
Dim vFirstChar, vTag As Variant
sTemp = ""
For Each cell In rng
sCell = cell.Value
vFirstChar = left(sCell, 1)
vTag = left(sCell, 3)
If IsNumeric(vFirstChar) = False And vTag <> "(S)" Then
sTemp = sTemp + sCell + " "
End If
Next
showOnlyNames = sTemp
End Function
Function showOnlyNumbs(rng As Range) As Variant ' Added Jan 17th to extract the phone number from any range of cells
Dim cell As Range
Dim sTemp, sCell As String
Dim vFirstChar As Variant
sTemp = ""
For Each cell In rng
sCell = cell.Value
vFirstChar = left(sCell, 1)
If IsNumeric(vFirstChar) Then
sTemp = sTemp + sCell + " "
End If
Next
showOnlyNumbs = sTemp
End Function
Function FontColor(CellColor As Range) ' Added Jan 10 -- to temp get font colors quickly
FontColor = CellColor.Font.ColorIndex
End Function
Function paidCOD(rng As Range) As Boolean ' Added Jan 10th -- function to see if COD is green
Dim color As Integer 'getting the color index
color = rng.Font.ColorIndex
paidCOD = False
Select Case color
Case 14, 24, 10, 56, 12, 48, 43, 12, 15, 35, 19 ' ALL GREEN AND BACK COLORS = DO NOT PRINT. from Andrei comp, I see 14, 48, 43, 56, 12, 35, 19 as greens.
paidCOD = True 'then yes, customer has paid cash on deliver (COD)
End Select
End Function
Function IsNum(data As Variant) ' Added Jan 5 11PM PETER PENG
' checks if it's a number.. DOES NOT guard against false positives like 45,50
If IsNumeric(data) Then
IsNum = True
Else
IsNum = False
End If
End Function
Function CheckNumStickers(n As String) As Integer
'this works by looping down the driver column until the driver changes... however,
'SOME STICKERS MAY BE BLANK IF NO ORDER ON THAT DAY
Dim i As Integer
i = 1
Dim colDriver2 As Integer
colDriver2 = colBasedOnTitle("ORDERS", " Driver")
Dim a, B As String
a = ActiveCell(i, colDriver2).Value
B = ActiveCell(i + 1, colDriver2).Value
Do While a = B
i = i + 1
a = ActiveCell(i, colDriver2).Value
B = ActiveCell(i + 1, colDriver2).Value
Loop
CheckNumStickers = i
End Function
Function CheckWsNameDup(n As String) As Boolean
'1.2 Function to check if a ws.Name already exisits
CheckWsNameDup = False
For Each ws In Worksheets
If n = ws.Name Then
CheckWsNameDup = True
Exit Function
End If
Next ws
End Function
Sub LabelMaker()
'
' Macro4 Macro ----------------- START BY the LABEL BUTTON ---------------------------------------------
'
ActiveCell.Select 'select the activated cell
' 0 Batch get column numbers from Clients tab
Dim colDrop, colTimeofD, colAllergiesNotes1, colFULLNAME, colPhone, colTag, colAddressLine1, colIntersection, colAllergiesNotes2, colSun, colWed As Integer
Dim colWedSPEC, colSunSPEC, colCOD, colDriver As Integer
Dim colPostal, colUnit, colCity As Integer
colDrop = colBasedOnTitle("ORDERS", "Drop") 'updated Feb 2016
colTimeofD = colBasedOnTitle("CLIENTS", "Time of D")
colAllergiesNotes1 = colBasedOnTitle("CLIENTS", "Allergies, Notes 1")
colFULLNAME = colBasedOnTitle("CLIENTS", "Full Name")
colPhone = colBasedOnTitle("CLIENTS", "Phone")
colDriver = colBasedOnTitle("ORDERS", " Driver")
'colSub = colBasedOnTitle("CLIENTS", "Sub")
colAddressLine1 = colBasedOnTitle("CLIENTS", "STREET NUMBER AND NAME")
colUnit = colBasedOnTitle("CLIENTS", "Unit")
colPostal = colBasedOnTitle("CLIENTS", "POSTAL CODE")
colCity = colBasedOnTitle("CLIENTS", "CITY")
colIntersection = colBasedOnTitle("CLIENTS", "Intersection")
colAllergiesNotes2 = colBasedOnTitle("CLIENTS", "Allergies, Notes 2")
colSun = colBasedOnTitle("ORDERS", "sun")
colWed = colBasedOnTitle("ORDERS", "wed")
colSunSPEC = colBasedOnTitle("ORDERS", "sSPEC")
colWedSPEC = colBasedOnTitle("ORDERS", "wSPEC")
colCOD = colBasedOnTitle("ORDERS", "COD")
Dim colBagsLastWeek, colBagsThisWeek As Integer
colBagsLastWeek = colBasedOnTitle("CLIENTS", "Bags Tot Last Week")
colBagsThisWeek = colBasedOnTitle("CLIENTS", "Bags Tot This Week")
'1. Check if right cell is selected ---- General pre-start error check -- else exit sub
If ActiveCell.Column <> 1 Then
MsgBox "Please make sure you have a Client ID (first column) selected to start"
Exit Sub
End If
'BUG SCANNER for forumlas, hidden rows, totals---------------
Dim Formula As String
Dim r, c, iBug, LastClientRow, NumbOfFormulaedCols As Integer
LastClientRow = GetLastClientRow ' got the bottom row that captures all client orders
NumbOfFormulaedCols = 11 'hard code the # of columns that you want checked
Dim colsWithFormulas() As Integer 'make arry
ReDim colsWithFormulas(1 To NumbOfFormulaedCols) ' redim arry
' formulaed cell cols are 6 to 12, 48 to 50, 53 to 61
colsWithFormulas(1) = colBasedOnTitle("ORDERS", "Bags Total")
colsWithFormulas(2) = colBasedOnTitle("ORDERS", "sun")
colsWithFormulas(3) = colBasedOnTitle("ORDERS", "wed")
colsWithFormulas(4) = colBasedOnTitle("ORDERS", "TOTAL")
colsWithFormulas(5) = colBasedOnTitle("ORDERS", "sTOT")
colsWithFormulas(6) = colBasedOnTitle("ORDERS", "wTOT")
colsWithFormulas(7) = colBasedOnTitle("ORDERS", "prog1")
colsWithFormulas(8) = colBasedOnTitle("ORDERS", "prog2")
colsWithFormulas(9) = colBasedOnTitle("ORDERS", "sunZero")
colsWithFormulas(10) = colBasedOnTitle("ORDERS", "wedZero")
colsWithFormulas(11) = colBasedOnTitle("ORDERS", "AllZero")
'THIS HAS TO MATCH THE ARRAYS TOTAL NUMBER, see lines above!!!
Dim FirstLetter, CellVal As String
Dim CheckedRows As Boolean
For r = 3 To LastClientRow 'ignore header and Promo row'
If CheckedRows = False Then
If Rows(r).Hidden = True Then 'ALSO CHECK HIDDEN ROWS
MsgBox ("HEADS UP: Row [ " + CStr(r) + " ] is hidden. This is a normal part of using Filters (from Row 1 Drop Down Arrow).")
CheckedRows = True 'so we only check once
End If
End If
For c = 1 To NumbOfFormulaedCols
CellVal = Cells(r, colsWithFormulas(c)).Formula
FirstLetter = left(CStr(CellVal), 1)
If FirstLetter <> "=" Then
MsgBox ("ERROR: the formula is missing at [ " + ConvertToLetter(colsWithFormulas(c)) + CStr(r) + " ] Column #" + CStr(colsWithFormulas(c)) + ". Please inspect. As a precaution, you may also want to inspect the entire row's formulas and hidden formulas (found to the right of Warnings columns). PS. to fix missing formulas, copy over a forumla from above or below the cell with the missing formula.")
Exit Sub
End If
Next 'row
Next 'col
'ALSO CHECK TOTAL SUMMATIONS:
'Dim colTOTAL, rowTOTALSstart, rowTOTALSend As Integer 'Totals column
'colTOTAL = colBasedOnTitle("ORDERS", "TOTAL")
'colTOTAL1 = colTOTAL + 1
'rowTOTALSstart = LastClientRow + 2 'move down 2 cells
'rowTOTALSend = LastClientRow + 5 ' move down 6 cells but minus 1 for the loop below
'Dim rr As Integer
'For rr = rowTOTALSstart To rowTOTALSend 'scan each summnation cell
' If Cells(rr, colTOTAL).Value <> Cells(rr + 1, colTOTAL).Value Then
' MsgBox ("ERROR: totals not matching at summation checks at the bottom of your sheet. Please inspect. Mismatched detecte on row " + CStr(rr))
' Exit Sub
' End If
'Next rr 'row
' Check if someone did not select the top row
If ActiveCell.Offset(-1, colDriver - 1).Value = ActiveCell.Offset(0, colDriver - 1).Value Then
If MsgBox("WARNING: it looks like you didn't select the first row of the drivers list, continue?", vbYesNo) = vbNo Then
Exit Sub
End If
End If
If ActiveCell.Row < 3 Then
MsgBox "Please do not make labels for the first and second row, that doesn't make sense :)"
Exit Sub
End If
If ActiveCell.Worksheet.Name <> "ORDERS" Then
MsgBox "Please make sure you are in the ORDERS tab. Remember to select the top Client ID cell and the program will 'waterfall' down until the driver changes"
Exit Sub
End If
If Application.WorksheetFunction.VLookup(ActiveCell, Worksheets("CLIENTS").Range("A:A"), 1) <> ActiveCell Then
MsgBox "This Client ID is not on your CLIENTS database."
Exit Sub
End If
'Check if user added a column
'If Range("AU:1") <> "TOTAL" Then ' HARD CODE change when changing columns
' MsgBox "WARNING - It looks like you've added or deleted a column, please revert back to a previous version or contact Akitasoft"
' Exit Sub
'End If
'Check if it's a Wednesday, sunday, or all sheet
' Grab the colum numbers of A1A and A1B
Dim tempNotesCol, i, sC1col, wC1col As Integer
tempNotesCol = colBasedOnTitle("ORDERS", "temp notes") 'hard code for temp notes header
sC1col = tempNotesCol + 1 'if one column to the right of "temp notes" is not hidden, then it must be sunday bc it's right beside it
wC1col = tempNotesCol + 17 'otherwise, check the first column that is a wednesday column
'later, this code will check if it's hidden or not to determine SUN vs WED
'Check for sunday or wed
' REMOVE FOR NOW TO SPEED UP BULK ORDER CODE March 10 2017 - BULK ORDER FEATURE
Dim SunOrWed As String ' DO NOT REMOVE THIS CODE
If Columns(sC1col).EntireColumn.Hidden = False And Columns(wC1col).EntireColumn.Hidden = False Then 'both wed and sun sheets are open
MsgBox "Please convert to either a Sunday or Wednesday sheet before making labels"
Exit Sub
ElseIf Columns(sC1col).EntireColumn.Hidden = False And Columns(wC1col).EntireColumn.Hidden = True Then ' it's a sunday sheet
SunOrWed = "Sunday"
ElseIf Columns(sC1col).EntireColumn.Hidden = True And Columns(wC1col).EntireColumn.Hidden = False Then
SunOrWed = "Wednesday"
Else
MsgBox "Something is not right; it looks like the columns have been shifted all out of place. Please double check your labels"
End If
'1.1 Checking number of stickers
Dim NumStickers As Integer
NumStickers = CheckNumStickers(ActiveCell.Address)
'1.2 Anchor the original activecell
Range(ActiveCell.Address).Name = "StartCell" ' Gives for example ORDERS!$A$2, I DONT KNOW HOW THIS LINE WORKS
'1.3 full recalc
Application.CalculateFullRebuild
'2. make new worksheet, name it after driver
Dim ws As Worksheet
Dim wsName As String
Dim tDriver As String
' handling multiple tabs
Dim wsSuffix As Integer
wsSuffix = 0
' taking the driver as tab name
tDriver = ActiveCell.Offset(0, colDriver - 1).Value 'grab driver name
wsName = tDriver
'if tab name already taken, this loops until it gets a new tab name
Do
If CheckWsNameDup(wsName) Then
wsSuffix = wsSuffix + 1
If wsSuffix >= 2 Then 'delete suffix from last time if it's pass 2nd tab
wsName = left(wsName, Len(wsName) - 1)
End If
'adding the name with a suffix
wsName = wsName + CStr(wsSuffix)
End If
Loop Until CheckWsNameDup(wsName) = False
If wsSuffix = 100 Then
MsgBox "Got 99 tabs but a bitch aint one, if you having to many tabs plz delete some son"
End If
' Show labels overview message to point to new tab
' wsName is the final worksheet name
'finally adding a ws as an object - ADJUST CELL HEIGHT AND WIDTH HERE -------------------------
Set ws = ThisWorkbook.Sheets.Add()
ws.Name = wsName
ws.Columns("A:B").ColumnWidth = 25.6
ws.Columns("C").ColumnWidth = 3.7
ws.Columns("D:E").ColumnWidth = 25.6
ws.Rows.RowHeight = 13.21
ws.Tab.color = 6 ' black?
'Page setup stuff ------------- TAB SETUP -------------------------
With ws.PageSetup
.Orientation = xlPortrait
.Zoom = 90
.FirstPageNumber = 2
.PaperSize = xlPaperLetter
.LeftMargin = Application.CentimetersToPoints(0.9)
.RightMargin = Application.CentimetersToPoints(0.3)
.TopMargin = Application.CentimetersToPoints(1.7)
.BottomMargin = Application.CentimetersToPoints(0.7)
.HeaderMargin = Application.InchesToPoints(0.1)
.FooterMargin = Application.InchesToPoints(0.1)
.PrintGridlines = False
' .TopMargin = Application.CentimetersToPoints(1.5) old margins..
' .BottomMargin = Application.CentimetersToPoints(0.9)
End With
'2.2 make a SECOND worksheet, name it after driver2 for addresses / route mapping - ADDRESS TAB
'removed
'Page setup stuff ------------- TAB SETUP FOR ROUTE MAP TAB-------------------------
'REMOVED
'go back to startcell
Application.Goto "StartCell"
' 3. Make left array
Dim L() As String
ReDim L(1 To 10, 1 To NumStickers * 3) As String
' 3.1 Make 1 x 10 array called "oneBy30" ****** ORIGINAL LABEL MAKER SECTION
Dim oneByTen(1 To 10), oneBy30(1 To 30) As String
Dim oCodeTempStore, oCodeTempStore1stRow, oCodeTempStore2ndRow As String
Dim rng, cell, rngCOD As Range ' create loop to read each column, make a rng object and set it
Dim rngTemp As String ' not sure but try it
' **************************************************
' IMPORTANT RNG : this captures the order field
' **************************************************
Set rng = Range(Cells(1, oStart("temp notes")), Cells(1, oEnd("TOTAL"))) ' for Order Fields - review this when adding columns -
'this should capture all the boxname row items ' CHANGE THIS IF ANDREI ADDS NEW MEAL - hard code
'this is rather Dynamic and usues Temp Notes and TOTAL to frame the range
Dim COD As String
Dim iSpecialMealCol As Integer
Dim sSpecial As String
Dim EmptyOrderCount, ZeroOrderHeadsUp As Integer
Dim clientID, clientIDrow As Integer
Dim xL, yL, iClientCol As Integer
' 3.3 - Bag _ of _ feature Feb 16 2015, further updated 2019
' 3.3.1 Create and pop and array with the iBag value, by looping from top to bottom. Since it's based on cell values, it does NOT need a buffer
Dim iB As Integer
Dim iBag() As Integer
ReDim iBag(1 To NumStickers) As Integer
Dim iBtemp As Integer
iBtemp = 0
For iB = 1 To NumStickers 'iB is the row that this loop waterfalls down on, it is dictated by the same driver
'get the actual ROW that the same client ID is in
clientIDrow = ActiveCell.Offset(iB - 1, 0).Row
EmptyOrderCount = 1
If SunOrWed = "Sunday" Then
EmptyOrderCount = Cells(clientIDrow, colSun).Value 'take how many meals ordered on Sun
ElseIf SunOrWed = "Wednesday" Then
EmptyOrderCount = Cells(clientIDrow, colWed).Value 'take how many meals ordered on Wed
End If
'Make sure we are doing non zeros
If EmptyOrderCount <> 0 Then
' if top AND bot pairs do not match eachother, then it's obivously a unique client, thus, bag 1
If Cells(clientIDrow, 1).Value <> Cells(clientIDrow - 1, 1).Value And Cells(clientIDrow, 1).Value <> Cells(clientIDrow + 1, 1).Value Then
iBag(iB) = 1
' if top pairs match, but bot pairs do not, it's the bottom of a 1 2 3 4 5 6 chain ( as an example).
ElseIf Cells(clientIDrow, 1).Value = Cells(clientIDrow - 1, 1).Value And Cells(clientIDrow, 1).Value <> Cells(clientIDrow + 1, 1).Value Then
iBtemp = iBtemp + 1
iBag(iB) = iBtemp ' so if the previous iB had a value of 2, then now this row has 3
iBtemp = 0 'it's at the end of the temp counter, reset counter
' if top pairs do NOT match, but bot pairs match, it's the top of a 1 2 3 4 5 6 chain. Start the counter at 1
ElseIf Cells(clientIDrow, 1).Value <> Cells(clientIDrow - 1, 1).Value And Cells(clientIDrow, 1).Value = Cells(clientIDrow + 1, 1).Value Then
iBtemp = 1
iBag(iB) = iBtemp
' if both top and bot pairs match, we are in the middle of that 123456 chain, climbing from top to bottom
ElseIf Cells(clientIDrow, 1).Value = Cells(clientIDrow - 1, 1).Value And Cells(clientIDrow, 1).Value = Cells(clientIDrow + 1, 1).Value Then
iBtemp = iBtemp + 1
iBag(iB) = iBtemp
End If
Else
iBag(iB) = 0 'if the first row is a 0 order then it's a 0
End If 'end of the statement that populates the iBag array
Next iB ' iB ... end of loop that figures out the Bag Numbers
iBtemp = 0
' Array iBag(1 to NumStickers) is now populated!
' 3.3.2 Time to pop iBagT() ; the total number of bags for this client
Dim iT As Integer
Dim iTotBags() As Integer
ReDim iTotBags(1 To NumStickers) As Integer ' same size as iBag()
For iT = NumStickers To 1 Step -1 ' Reverse loop aww yea. Climbing from bottom to top to catch the largest number in a 12345 bag sequence
'get the actual ROW that the same client ID is in
clientIDrow = ActiveCell.Offset(iT - 1, 0).Row
If iBag(iT) <> 0 Then
' if top and bot pairs DO NOT match eachother, then it's obivously a unique client, thus, total bag is 1
If Cells(clientIDrow, 1).Value <> Cells(clientIDrow - 1, 1).Value And Cells(clientIDrow, 1).Value <> Cells(clientIDrow + 1, 1).Value Then
iTotBags(iT) = 1
' if top pairs match, but bot pairs do not, it's the bottom of a 1 2 3 4 5 6 chain for sure ( as an example). Take the 6 as anchor
ElseIf Cells(clientIDrow, 1).Value = Cells(clientIDrow - 1, 1).Value And Cells(clientIDrow, 1).Value <> Cells(clientIDrow + 1, 1).Value Then
iTotBags(iT) = iBag(iT) ' taking the 6 (just as an example) as the anchor
iBtemp = iBag(iT) ' store this as an anchor, this COULD NOT BE A ZERO since we are in the <> 0 if statement
' if top pairs do NOT match, but bot pairs match, it's the top of a 1 2 3 4 5 6 chain for sure. Take the old anchor but reset counter
ElseIf Cells(clientIDrow, 1).Value <> Cells(clientIDrow - 1, 1).Value And Cells(clientIDrow, 1).Value = Cells(clientIDrow + 1, 1).Value Then
If iBtemp = 0 Then 'if some how the sequence is 1 0 0 0 0 0 .. well the iBtemp is still set to zero. that is not cool, make if statement for this
iTotBags(iT) = iBag(iT) 'this should always be a 1
Else
iTotBags(iT) = iBtemp ' taking the anchor and then reset anchor
iBtemp = 0
End If
' if both top and bot pairs match, we are in the middle of that 123456 chain, climbing from bottom to top, but top and bot can be flanked by zeros too
' for ex... 0 0 0 1 0 0 2 0 really messes things up
' if we did not take anchor already, then chances are it's the largest number (the 2) for sure
' else, we should just take the old anchor
ElseIf Cells(clientIDrow, 1).Value = Cells(clientIDrow - 1, 1).Value And Cells(clientIDrow, 1).Value = Cells(clientIDrow + 1, 1).Value Then
If iBtemp = 0 Then 'if the anchor was not already taken
iTotBags(iT) = iBag(iT) ' taking the iBag value as the anchor
iBtemp = iBag(iT) ' store this as an anchor
Else
iTotBags(iT) = iBtemp 'else, some anchor was already taken, this means the loop found the biggest value already. Use that anchor
End If 'Btemp <> 0 Then '
Else 'this should not be possible
MsgBox "The column A (CID) has been corrupted. Please contact Peter"
Exit Sub
End If ' of If Cells(clientIDrow, 1).Value <> Cells(clientIDrow - 1, 1).Valu..........
Else
iTotBags(iT) = 0
End If
Next 'iT end of loop that starts from bottom of the array and pops the Total Bag count
' Cleared test pit @ 8:28 pm Feb 17
For iB = 1 To NumStickers
Debug.Print ("Bag " + CStr(iBag(iB)) + " of " + CStr(iTotBags(iB)))
Next
' 3.3.3 Populate final Bag _ of _ string, compressed in 2019
Dim sBagLabel() As String
ReDim sBagLabel(1 To NumStickers) As String
For i = 1 To NumStickers
sBagLabel(i) = "Bag" + CStr(iBag(i)) + "/" + CStr(iTotBags(i))
Next
' ---------------ADDRESSES TAB FEATURE --------------------- Feb 2016
' 3.3.4 creat matrix to store addresses for joyeco to make a tab like this:
'Column 1+1 - Name - G
'Column 2+1 - Phone number - H
'Column 3+1 - Address 1 - J
'Column 4+1 - Address 2 - K
'Column 5+1 - Intersection - L
'Column 6+1- Notes 1 - F
'Column 7+1- Notes 2 - M
'Column 1 - Drop #
Dim sAddresses() As String
Dim AddressTotCols As Integer
AddressTotCols = 12 'hard code this for the address tab feature
ReDim sAddresses(1 To NumStickers, 1 To AddressTotCols) As String ' second dimensions is the number of columns in address tabs
' ---------------DROP COUNTER FEATURE --------------------- Feb 2016
' Feb 2016 New feature: DROP COUNTER
' This feature is not so simple, because you can't simply take the total unique ID's and minus the number of ZeroOrders, this is because if one customer has MULTIPLE
' zero orders in one day, that only counts as ONE less drop
'Solution, make a two dimenion array, first col is Client ID, second column is the order count on Sun and Wed column:
'101 6
'101 5
'102 6
'102 6
'103 6
'103 0
'103 0
'in the above scneario, the total drop would be 3. Therefore, make a function that FIRST, takes all unique values (3), then minus the zeros (which is 1, not 2)
Dim DropNum As String ' used for the FIRST part of the drop # msg
'Dim bugStop As String ' store array to view
Dim cIDs() As Integer ' array to hold all CIDs and also the Sun or Wed bag count, unknown size
ReDim cIDs(1 To NumStickers) As Integer 'size the array, does not account for blankstickers, remember to aacount for ZeroOrderHeadsUp
Dim DropTotal As Integer
Dim zeroCounterDrop As Integer
zeroCounterDrop = 0
Dim OrderCodeTemp, s, firstChar, lastChar As String
Dim Lfiltered, Afiltered, Bfiltered, ExcludeFiltered As String
'
'**************************************************************************'
'------------------- KEY SECTION --------------------------------- CORE CODE
'------------------- ONE BY TEN MATRIX POPULATION ---------------- CORE CODE
' this matrix makes a 1x10 array and puts important info on each stick on here, beginning with the order code to the address
' the followup part of this code plots each 1x10 matrix into the right arrangement of boxes
For yL = 1 To NumStickers 'yL is the row that this loop waterfalls down on, it is decitated by the same driver
'get the client ID for vlookup purposes
clientID = ActiveCell.Offset(yL - 1, 0).Value
'get the actual ROW that the same client ID is in
clientIDrow = ActiveCell.Offset(yL - 1, 0).Row
'If it's a sun sheet, check wed order numb
EmptyOrderCount = 1
If SunOrWed = "Sunday" Then
EmptyOrderCount = Cells(clientIDrow, colSun).Value
ElseIf SunOrWed = "Wednesday" Then
EmptyOrderCount = Cells(clientIDrow, colWed).Value
End If
'BAG DROP TOTAL counter starts here.
'get the client ID for Drop counter 2D array and then the Sun/Wed bag count
If EmptyOrderCount > 0 And EmptyOrderCount < 7 Then
cIDs(yL) = clientID 'now we have a populated cIDs array with ALL cIDs, next step is to count the uniq IDs, but don't count the unique ID's that have a ZeroOrder associated with it
ElseIf EmptyOrderCount < 0 And EmptyOrderCount > 6 Then
MsgBox "Someone ordered a number of bags that doesn't make sense, please check the Sunday or Wednesday totals"
Exit Sub
Else
cIDs(yL) = 0
zeroCounterDrop = zeroCounterDrop + 1
End If
'find "count unique drops" for next step"
'SAMPLE OF a cID array
'101 6 turns into 101
'101 5 101
'102 6 102
'102 6 102
'103 6 103
'103 0 0
'103 0 0
'bugStop = bugStop + " " + CStr(cIDs(yL)) 'passed bugstop 7:20pm
' The 1 x 10 popping starts here:
If EmptyOrderCount <> 0 Then ' make sure it's not a zero order
'pop a 1 x 30 array from the clients tab, this saves me from vlookuping too much
For iClientCol = 1 To 30
'vlookup for a A2:AD1000 wide net -- this is a lot of data and it's a hard code - could make it efficient and faster by finding a way to limit the scan
oneBy30(iClientCol) = CStr(Application.VLookup(clientID, Worksheets("CLIENTS").Range("A2:AD10000"), iClientCol))
'this pops the 1 by 30 array
'iClientCol <== this is to count the number of column to scan the CLIENTS tab, right now it's set to 30
Next
'(1) Order code goes here
'NEW in March 2019: Seperate the 1 row of order code into two
' more about rng (range), this range captures all order codes from the row of cells which are framed by 2 hard-coded column names
'In an earlier sectuion, the code looked like this to create rng:
' Set rng = Range(Cells(1, oStart("temp notes")), Cells(1, oEnd("TOTAL"))) ' for Order Fields - review this when adding columns -
'this should capture all the boxname row items ' CHANGE THIS IF ANDREI ADDS NEW MEAL - hard code
'this is rather Dynamic and usues Temp Notes and TOTAL to frame the range'
For Each cell In rng '--- loop through Range rng object
'if the meal column (A1, A2, etc) is not hidden and it's more than 0, then:
If cell.Columns.Hidden = False And Cells(clientIDrow, cell.Column).Value > 0 Then
' ---------- CLEAN UP ORDER CODE BEFORE PLOTTING INTO MATRIX HERE
' b/c the un cleaned values look like this:
'.A1B .A2B .A3B .A4B .A5B .A6B .L7B .L8 .L9B .L10B .L11B .L12 .B4B .B5B .B6B PR1 PR2 PR3 PR4
'
'how to get first char Dim s = "Character"
' Dim firstChar = s(0)
'how to get last char: Right(1,string_name)
s = CStr(cell.Value)
firstChar = CStr(left(s, 1))
lastChar = CStr(right(s, 1))
'only clip off end if it has A or B, because this states for Menu A or B
If lastChar = "A" Then
OrderCodeTemp = left(s, Len(s) - 1) 'classic Left excel function
ElseIf lastChar = "B" Then
OrderCodeTemp = left(s, Len(s) - 1) 'classic Left excel function
Else
OrderCodeTemp = s
End If
' TEST PIT MsgBox (firstChar & " " & lastChar)
'if the meal quantity is 1 then there is no "x1" next to the order code, so we have two situations here below:
If Cells(clientIDrow, cell.Column).Value = 1 Then
'put order code in a temp holder but NO x1's - June 2016
' how to clip off lat char of string if it's A or B: Left(myString, Len(myString) - 1)
' --------------------------------------------------------------------------------------
' meal name umber of meals
oCodeTempStore = oCodeTempStore + OrderCodeTemp + " " 'NO x1 if it's only 1 meal
Else
oCodeTempStore = oCodeTempStore + OrderCodeTemp + "x" + CStr(Cells(clientIDrow, cell.Column).Value) + " "
' --------------------------------------------------------------------------------------
End If
End If ' of the order code
Next 'in rng for order code
'NEW March 2019 feature; oCodeTempStore has to be SORTED into 4 quadrants:
' LIFESTYLE -- Bulk
' ATHLETE -- BREAKFAST
'here are ALL POSSIBLE MEAL CODES as for 2019:
' A1B A2B A3B A4B A5B A6B L1B L2B L3B L4B L5B L6B B1 B2 B3B .A1B .A2B .A3B .A4B .A5B .A6B .L7B .L8 .L9B .L10B .L11B .L12 .B4B .B5B .B6B
' PR1 PR2 PR3 PR4 PR5 PR6 CA1 CA2 CA3 CA4 CA5 CA6 GR1 GR2 GR3 PR1 PR2 PR3 PR4 PR5 PR6 CA1 CA2 CA3 CA4 CA5 CA6 GR1 GR2 GR3'
'Overal, we need to filter and spilt each order snipit by the first letter (not . tho), into 4 categories
'then we need to put them into two rows: oCodeTempStore1stRow and oCodeTempStore2ndRow
'if there is only 1 category, remove the splitter --'
'ideal code:
'oCodeTempStore1stRow = filterfunction(oCodeTempStore,L) + "---" + filterfunction(oCodeTempStore,Any)
'oCodeTempStore2stRow = filterfunction(oCodeTempStore,A) + "---" + filterfunction(oCodeTempStore,B)
If Len(oCodeTempStore) > 1 Then
'start putting in filtered strings as per dimmed earlier: Dim Lfiltered, Afiltered, Bfiltered, ExcludeFiltered As String'
Lfiltered = OrderFilter(oCodeTempStore, "L")
Afiltered = OrderFilter(oCodeTempStore, "A")
Bfiltered = OrderFilter(oCodeTempStore, "B")
ExcludeFiltered = OrderExcludeFilter(oCodeTempStore, "L", "A", "B", "*")
' FIRST ROW POPULATION, based on if the L or Any filters are present or not'
If Len(ExcludeFiltered) > 1 Then
oCodeTempStore1stRow = Lfiltered + " -- " + ExcludeFiltered
Else
oCodeTempStore1stRow = Lfiltered + " " + ExcludeFiltered
End If
' 2ND ROW POPULATION, same logic'
If Len(Bfiltered) > 1 Then
oCodeTempStore2ndRow = Afiltered + " -- " + Bfiltered
Else
oCodeTempStore2ndRow = Afiltered + " " + Bfiltered
End If
Else
oCodeTempStore1stRow = ""
oCodeTempStore2ndRow = ""
End If
'**********************************************************'
'* Putting values into 1x10 materix for the addres labels *'
'*********************************************************
' June 2016 put order code into where the WWW used to be:
oneByTen(1) = oCodeTempStore1stRow ' Adding CStr(EmptyOrderCount) would give the total number of meals in this bag
oCodeTempStore = " " 'reset tempstore after the yL loop
oCodeTempStore1stRow = " "
oneByTen(2) = oCodeTempStore2ndRow
oCodeTempStore2ndRow = " "
'(3.1) SPECIALS
If SunOrWed = "Sunday" Then 'grab the special column depending on sun or wed
iSpecialMealCol = colSunSPEC
Else
iSpecialMealCol = colWedSPEC
End If
If Cells(clientIDrow, iSpecialMealCol).Value > 0 Then 'there really is a special
sSpecial = "*" + CStr(Cells(clientIDrow, iSpecialMealCol).Value) + "xSPECIAL*" 'populate the special code
ElseIf IsNum(Cells(clientIDrow, iSpecialMealCol).Value) = False Then
MsgBox ("Stoping the program because some strange text or blank was put in the SPECIAL field, row [ " + CStr(clientIDrow) + " ], please recheck values and remake labes :)")
Exit Sub
Else
sSpecial = ""
End If
'(3.1.1) Bags with client feature - Aug 2016 - added new column in Clients tab, updated 2019 to remove this row and use it to store the Order Code as a 2nd row
'(3.2) THREE VARIALBES in 1 CELL: SPECIALS + BAG _ OF _ + BAGS: , updated 2019 PP
oneByTen(3) = sSpecial + " " + sBagLabel(yL) + " BAGS:" + CStr(oneBy30(colBagsLastWeek)) ' add this number from the bags w client field in the CLIENTS tab, add it to the 2nd cell in the label
'(4) Area code, evening/morning delivery, and COD USED TO GO here:
' Now switch to just showing the Drop # and COD (Feb 2016)
' but first IS THERE A COD? if it's a normal one, add a $ sign
rngTemp = Cells(clientIDrow, colCOD).Address(RowAbsolute:=False, ColumnAbsolute:=False) ' store a Range for the paidCOD function
Set rngCOD = Range(rngTemp)
If IsNum(Cells(clientIDrow, colCOD).Value) And Cells(clientIDrow, colCOD).Value > 0 And paidCOD(rngCOD) = False Then ' if it's a legit COD$ ,add a $
COD = " COD: $" + CStr(Cells(clientIDrow, colCOD).Value)
ElseIf IsNum(Cells(clientIDrow, colCOD).Value) And Cells(clientIDrow, colCOD).Value <= 0 Then ' if it's some weird 0 or something, don't add a $
COD = CStr(Cells(clientIDrow, colCOD).Value)
ElseIf IsEmpty(Cells(clientIDrow, colCOD).Value) Or paidCOD(rngCOD) = True Then 'if it's empty OR the client has already paid, don't do anything
COD = ""
Else 'Then it's some weird text or something, warn user, then continue if he selects YES
If MsgBox("There is a COD that does not have a regular number on row [ " + CStr(clientIDrow) + " ], it reads as [ " + CStr(Cells(clientIDrow, colCOD).Value) + " ]. Shall we continue anyways?", vbYesNo) = vbYes Then
COD = CStr(Cells(clientIDrow, colCOD).Value)
Else
MsgBox ("Stoping the program because some strange text or blank was put in COD, row [ " + CStr(clientIDrow) + " ], please recheck values and remake labes :)")
Exit Sub
End If 'of the MsgBox stuff
End If 'of the COD statement
'(4) continued Drop Counter + COD
' oneByTen(4) = oneBy30(colACode) + " " + oneBy30(colTimeofD) + " " + COD 'deleted Feb 2016
DropNum = Cells(clientIDrow, colDrop).Value 'get drop dirctly from Drop column
oneByTen(4) = " Drop " + CStr(DropNum) + " " + COD 'deleted Feb 2016 ADD DROP feature later
'(5) allergies and notes 1
oneByTen(5) = " " + oneBy30(colAllergiesNotes1)
'(6) to (10). data for second column in a sticker. all from CLIENTS TAB
oneByTen(6) = oneBy30(colFULLNAME) + " " + oneBy30(colPhone) ' full name and number
oneByTen(7) = oneBy30(colAddressLine1) + " " + oneBy30(colUnit) ' address 1 and unit
oneByTen(8) = oneBy30(colCity) + " " + oneBy30(colPostal)
oneByTen(9) = oneBy30(colIntersection) ' intersection
oneByTen(10) = oneBy30(colAllergiesNotes2) ' allergies and notes 2
' ---ADDRESS FEATURE
'Column 1+1 - Name - G
'Column 2+1 - Phone number - H
'Column 3+1 - Address 1 - J
'Column 4+1 - Address 2 - K
'Column 5+1 - Intersection - L
'Column 6+1- Notes 1 - F
'Column 7+1- Notes 2 - M
'Column 1 - Drop #
'removed
Else 'it's a zero order
' there is some sort of IF statement that forces me to add longer strings to the array as oppose to tiny strings
oneByTen(1) = " "
oneByTen(2) = " "
oneByTen(3) = " "
oneByTen(4) = " "
oneByTen(5) = " "
oneByTen(6) = " "
oneByTen(7) = " "
oneByTen(8) = " "
oneByTen(9) = " "
oneByTen(10) = " "
ZeroOrderHeadsUp = ZeroOrderHeadsUp + 1 'keep track of number of times a zero order was filled
End If
' get out of the program if NO stickers are about to be make
If ZeroOrderHeadsUp = NumStickers Then
MsgBox ("No orders were placed for ANY of the drivers you selected, please double check your Sunday's vs Wednesday's")
Exit Sub
End If
' 3.2 pop 1x10 arrary into full left array before moving on to the next one
For xL = 1 To 10
L(xL, yL) = oneByTen(xL) 'the L() matrix
Next 'xL
' return to anchor
Application.Goto "StartCell"
Next 'yL
'4. Add 4 spaces after every 2 in L()
Dim yy, xx, y, sixCounter, NumStickersTimesThree As Integer ' counter keeps a 6-cycle count
Dim LL() As String
NumStickersTimesThree = NumStickers * 3
ReDim LL(1 To 10, 1 To NumStickersTimesThree) As String
xx = 1
yy = 1
y = 1
sixCounter = 1
For yy = 1 To NumStickersTimesThree ' Loop to pop LL()
' THIS THING DOES STUFF I CANT EXPLAIN
If sixCounter = 7 Then
sixCounter = 1
End If ' F U sixCounter!
Select Case sixCounter
Case 1 To 2 ' if it's the first 2 rows
xx = 1
For xx = 1 To 10 'fill all 10 columns in LL() with L() equivlant
LL(xx, yy) = L(xx, y)
' LL(xx, yy) = "counter is 1 to 2. X:" + CStr(xx) + " Y:" + CStr(yy) 'L(xx, yy) ---- This was a debugger
Next xx
y = y + 1
sixCounter = sixCounter + 1
Case 3 To 6 'if it's the 3rd to 6th row, make blanks
xx = 1
For xx = 1 To 10 'fill all 10 columns in LL() with BLANKS
LL(xx, yy) = ""
'LL(xx, y) = "counter is 3 to 6. X:" + CStr(xx) + " Y:" + CStr(y) 'suppose to be actual blank
Next xx
sixCounter = sixCounter + 1
End Select
Next yy
'------------- COUNT UNIQUE DROPS ------------------------------------------------------------
Dim UniqueCIDDropCounter As Integer
If zeroCounterDrop = 0 Then
UniqueCIDDropCounter = UniqueItems(cIDs, True)
Else
UniqueCIDDropCounter = UniqueItems(cIDs, True) - 1
End If
'--------------------- PRINTING THE FINAL LABEL SHEET HERE via MATRIX LL() ----------------------------
Dim x As Integer
Dim firstColSticker As Boolean
firstColSticker = True
x = 1
y = 1
yy = 1
For y = 1 To NumStickersTimesThree ' ====> y represent each row in the LL() array
If Len(LL(1, y)) > 1 And firstColSticker = True Then ' if the length of the first cell in the LL() array (www.onelife) is not blank, then
yy = 1