1: Sub Summary()
2: '
3: ' Summary Macro
4: '
5: 6: '
7: Application.ScreenUpdating = False
8: 9: ' M ---------------------------------------------------------------------
10: 11: Sheets("M").Select
12: Range("B2:B11,G2:G11").Select
13: Selection.Copy14: Sheets("Raw Drops - Summary").Select
15: Range("C4").Select
16: Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _17: :=False, Transpose:=False
18: 19: Dim i As Integer
20: Dim j As Integer
21: Dim k As Integer
22: Dim R1 As Integer
23: Dim Cells1 As String
24: 25: R1 = 4 26: 27: For j = 1 To 10
28: 29: Sheets("M - Cells").Select
30: If j = 1 Then
31: 32: k = 2 33: 34: End If
35: 36: For i = 1 To 31
37: 38: If i = 1 Then
39: 40: Cells1 = Cells(i + k, 13) 41: 42: Else
43: 44: If (Cells(i + k, 13).Value <> "") Then
45: 46: If (Cells(i + k, 13).Value <> Cells(i + k - 1, 13).Value) Then
47: 48: Cells1 = Cells1 + ", " + Cells(i + k, 13)
49: 50: End If
51: 52: Else
53: 54: k = Cells(i + k, 13).Row55: Exit For
56: 57: End If
58: 59: End If
60: 61: Next i
62: 63: Sheets("Raw Drops - Summary").Select
64: Cells(R1, 5) = Cells1 65: 66: R1 = R1 + 1 67: 68: Next j
69: 70: ' A ---------------------------------------------------------------------
71: 72: Sheets("A").Select
73: Range("B2:B11,G2:G11").Select
74: Application.CutCopyMode = False
75: Selection.Copy76: Sheets("Raw Drops - Summary").Select
77: Range("C14").Select
78: Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _79: :=False, Transpose:=False
80: 81: Cells1 = ""
82: R1 = 14 83: 84: For j = 1 To 10
85: 86: Sheets("A - Cells").Select
87: If j = 1 Then
88: 89: k = 2 90: 91: End If
92: 93: For i = 1 To 31
94: 95: If i = 1 Then
96: 97: Cells1 = Cells(i + k, 13) 98: 99: Else
100: 101: If (Cells(i + k, 13).Value <> "") Then
102: 103: If (Cells(i + k, 13).Value <> Cells(i + k - 1, 13).Value) Then
104: 105: Cells1 = Cells1 + ", " + Cells(i + k, 13)
106: 107: End If
108: 109: Else
110: 111: k = Cells(i + k, 13).Row112: Exit For
113: 114: End If
115: 116: End If
117: 118: Next i
119: 120: Sheets("Raw Drops - Summary").Select
121: Cells(R1, 5) = Cells1 122: 123: R1 = R1 + 1 124: 125: Next j
126: 127: Range("A1").Select
128: 129: Application.ScreenUpdating = True
130: 131: End Sub
1: Sub Worse_B()
2: '
3: ' Worse_B Macro
4: '
5: Dim Filename1 As String
6: Dim Filename2 As String
7: Dim Filename3 As String
8: Dim Path1 As String
9: Dim Day1 As String
10: Dim Day2 As String
11: Dim Day3 As String
12: 13: Sheets("Main Menu").Select
14: Filename1 = Range("D2").Text
15: Filename2 = Range("D3").Text
16: Filename3 = Range("C8").Text
17: Path1 = Range("C2").Text
18: Day1 = Range("C4").Text
19: Day2 = Range("C5").Text
20: Day3 = Range("C6").Text
21: 22: Application.ScreenUpdating = False
23: 24: ' M------------------------------------------------------------------------
25: 26: Workbooks.Open Filename:=Path1 + Filename1 27: 28: Windows(Filename1).Activate29: ActiveSheet.Range("$A$1:$I$3000").AutoFilter Field:=3, Criteria1:=Day1
30: Range("A2:I2").Select
31: Range(Selection, Selection.End(xlDown)).Select
32: Selection.Copy 33: Windows(Filename3).Activate34: Sheets("M - Day1").Select
35: Range("A2").Select
36: ActiveSheet.Paste 37: 38: Windows(Filename1).Activate39: ActiveSheet.Range("$A$1:$I$3000").AutoFilter Field:=3, Criteria1:=Day2
40: Range("A2:I2").Select
41: Range(Selection, Selection.End(xlDown)).Select
42: Selection.Copy 43: Windows(Filename3).Activate44: Sheets("M - Day2").Select
45: Range("A2").Select
46: ActiveSheet.Paste 47: 48: Windows(Filename1).Activate49: ActiveSheet.Range("$A$1:$I$3000").AutoFilter Field:=3, Criteria1:=Day3
50: Range("A2:I2").Select
51: Range(Selection, Selection.End(xlDown)).Select
52: Selection.Copy 53: Windows(Filename3).Activate54: Sheets("M - Day3").Select
55: Range("A2").Select
56: ActiveSheet.Paste 57: 58: Application.CutCopyMode = Flase59: Workbooks(Filename1).Close savechanges:=False
60: 61: Sheets("M").Select
62: Range("C2").Select
63: ActiveCell.FormulaR1C1 = _64: "=IF(ISNA(VLOOKUP(RC[-1],'M - Day1'!R2C2:R347C9,8,FALSE)),0,VLOOKUP(RC[-1],'M - Day1'!R2C2:R347C9,8,FALSE))"
65: Range("C2").Select
66: Selection.AutoFill Destination:=Range("C2:C347")
67: 68: Range("D2").Select
69: ActiveCell.FormulaR1C1 = _70: "=IF(ISNA(VLOOKUP(RC[-2],'M - Day2'!R2C2:R347C9,8,FALSE)),0,VLOOKUP(RC[-2],'M - Day2'!R2C2:R347C9,8,FALSE))"
71: Range("D2").Select
72: Selection.AutoFill Destination:=Range("D2:D347")
73: 74: Range("E2").Select
75: ActiveCell.FormulaR1C1 = _76: "=IF(ISNA(VLOOKUP(RC[-3],'M - Day3'!R2C2:R347C9,8,FALSE)),0,VLOOKUP(RC[-3],'M - Day3'!R2C2:R347C9,8,FALSE))"
77: Range("E2").Select
78: Selection.AutoFill Destination:=Range("E2:E347")
79: 80: Range("G2").Select
81: ActiveCell.FormulaR1C1 = _82: "=IF(ISNA(VLOOKUP(LEFT(RC[-5],6),'" + Path1 + "[O.xls]Locked Sites'!R2C4:R65C5,2,FALSE)),SUM(RC[-4]:RC[-2]),0)"
83: Range("G2").Select
84: Selection.AutoFill Destination:=Range("G2:G347")
85: 86: ActiveWorkbook.Worksheets("M").AutoFilter.Sort.SortFields.Clear
87: ActiveWorkbook.Worksheets("M").AutoFilter.Sort.SortFields.Add Key:= _
88: Range("G1"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
89: xlSortNormal90: With ActiveWorkbook.Worksheets("M").AutoFilter.Sort
91: .Header = xlYes92: .MatchCase = False
93: .Orientation = xlTopToBottom 94: .SortMethod = xlPinYin 95: .Apply96: End With
97: 98: ' A -------------------------------------------------------------------------
99: 100: Workbooks.Open Filename:=Path1 + Filename2 101: 102: Windows(Filename2).Activate103: ActiveSheet.Range("$A$1:$H$3000").AutoFilter Field:=3, Criteria1:=Day1
104: Range("A2:H2").Select
105: Range(Selection, Selection.End(xlDown)).Select
106: Selection.Copy 107: Windows(Filename3).Activate108: Sheets("A - Day1").Select
109: Range("A2").Select
110: ActiveSheet.Paste 111: 112: Windows(Filename2).Activate113: ActiveSheet.Range("$A$1:$H$3000").AutoFilter Field:=3, Criteria1:=Day2
114: Range("A2:H2").Select
115: Range(Selection, Selection.End(xlDown)).Select
116: Selection.Copy 117: Windows(Filename3).Activate118: Sheets("A - Day2").Select
119: Range("A2").Select
120: ActiveSheet.Paste 121: 122: Windows(Filename2).Activate123: ActiveSheet.Range("$A$1:$H$3000").AutoFilter Field:=3, Criteria1:=Day3
124: Range("A2:H2").Select
125: Range(Selection, Selection.End(xlDown)).Select
126: Selection.Copy 127: Windows(Filename3).Activate128: Sheets("A - Day3").Select
129: Range("A2").Select
130: ActiveSheet.Paste 131: 132: Application.CutCopyMode = False
133: Workbooks(Filename2).Close savechanges:=False
134: 135: Sheets("A").Select
136: Range("C2").Select
137: ActiveCell.FormulaR1C1 = _138: "=IF(ISNA(VLOOKUP(RC[-1],'A - Day1'!R2C2:R314C8,7,FALSE)),0,VLOOKUP(RC[-1],'A - Day1'!R2C2:R314C8,7,FALSE))"
139: Range("C2").Select
140: Selection.AutoFill Destination:=Range("C2:C314")
141: 142: Range("D2").Select
143: ActiveCell.FormulaR1C1 = _144: "=IF(ISNA(VLOOKUP(RC[-2],'A - Day2'!R2C2:R314C8,7,FALSE)),0,VLOOKUP(RC[-2],'A - Day2'!R2C2:R314C8,7,FALSE))"
145: Range("D2").Select
146: Selection.AutoFill Destination:=Range("D2:D314")
147: 148: Range("E2").Select
149: ActiveCell.FormulaR1C1 = _150: "=IF(ISNA(VLOOKUP(RC[-3],'A - Day3'!R2C2:R314C8,7,FALSE)),0,VLOOKUP(RC[-3],'A - Day3'!R2C2:R314C8,7,FALSE))"
151: Range("E2").Select
152: Selection.AutoFill Destination:=Range("E2:E314")
153: 154: ActiveWorkbook.Worksheets("A").AutoFilter.Sort.SortFields.Clear
155: ActiveWorkbook.Worksheets("A").AutoFilter.Sort.SortFields.Add Key:= _
156: Range("G1"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
157: xlSortNormal158: With ActiveWorkbook.Worksheets("A").AutoFilter.Sort
159: .Header = xlYes160: .MatchCase = False
161: .Orientation = xlTopToBottom 162: .SortMethod = xlPinYin 163: .Apply164: End With
165: 166: Sheets("Main Menu").Select
167: Range("A1").Select
168: 169: Application.ScreenUpdating = True
170: 171: End Sub
1: Sub Worse_C()
2: '
3: ' Worse_C Macro
4: '
5: Dim BN As String
6: Dim Range1 As Range
7: Dim R1 As Integer
8: Dim R2 As Integer
9: Dim R3 As Integer
10: Dim i As Integer
11: Dim j As Integer
12: Dim Filename1 As String
13: Dim Filename2 As String
14: Dim Filename3 As String
15: Dim Path1 As String
16: Dim Days1(1 To 3) As String
17: 18: Sheets("Main Menu").Select
19: 20: Days1(1) = Range("C4").Text
21: Days1(2) = Range("C5").Text
22: Days1(3) = Range("C6").Text
23: 24: Filename2 = Range("C8").Text
25: Filename1 = Range("D13").Text
26: Filename3 = Range("D14").Text
27: Path1 = Range("C2").Text
28: 29: Application.ScreenUpdating = False
30: 31: Sheets("M - C").Select
32: Range("A2:K500").Select
33: With Selection.Interior
34: .Pattern = xlNone 35: .TintAndShade = 0 36: .PatternTintAndShade = 037: End With
38: Selection.ClearContents 39: 40: R2 = C(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
41: 42: Range(C(R2, 1), C(R2, 11)).Select
43: With Selection.Interior
44: .Pattern = xlSolid 45: .PatternColorIndex = xlAutomatic 46: .ThemeColor = xlThemeColorDark2 47: .TintAndShade = -0.249977111117893 48: .PatternTintAndShade = 049: End With
50: 51: Sheets("A - C").Select
52: Range("A2:K500").Select
53: With Selection.Interior
54: .Pattern = xlNone 55: .TintAndShade = 0 56: .PatternTintAndShade = 057: End With
58: Selection.ClearContents 59: 60: R3 = C(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
61: 62: Range(C(R3, 1), C(R3, 11)).Select
63: With Selection.Interior
64: .Pattern = xlSolid 65: .PatternColorIndex = xlAutomatic 66: .ThemeColor = xlThemeColorDark2 67: .TintAndShade = -0.249977111117893 68: .PatternTintAndShade = 069: End With
70: 71: ActiveWorkbook.Save 72: 73: ' M ------------------------------------
74: 75: R1 = 2 76: 77: Workbooks.Open Filename:=Path1 + Filename1 78: 79: For i = 1 To 10
80: 81: Windows(Filename2).Activate82: Sheets("M").Select
83: C(R1, 2).Select
84: BN = ActiveCell.Text 85: 86: For j = 1 To 3 ' j Loop Start-------------------
87: 88: Windows(Filename1).Activate89: Rows("1:1").Select
90: Selection.AutoFilter91: ActiveSheet.Range("$A$1:$K$33384").AutoFilter Field:=2, Criteria1:=BN
92: ActiveSheet.Range("$A$1:$K$33384").AutoFilter Field:=5, Operator:= _
93: xlFilterValues, Criteria2:=Array(2, Days1(j))94: Range("A2").Select
95: Range(Selection, Selection.End(xlToRight)).Select
96: Range(Selection, Selection.End(xlDown)).Select
97: Selection.Copy 98: Windows(Filename2).Activate99: Sheets("M - Working").Select
100: Range("A2").Select
101: ActiveSheet.Paste102: Application.CutCopyMode = False
103: ActiveWorkbook.Worksheets("M - Working").AutoFilter.Sort.SortFields.Clear
104: ActiveWorkbook.Worksheets("M - Working").AutoFilter.Sort.SortFields.Add Key:= _
105: Range("K1:K131"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption _
106: :=xlSortNormal107: With ActiveWorkbook.Worksheets("M - Working").AutoFilter.Sort
108: .Header = xlYes109: .MatchCase = False
110: .Orientation = xlTopToBottom 111: .SortMethod = xlPinYin 112: .Apply113: End With
114: 115: Range("M1").Select
116: Set Range1 = ActiveCell
117: Range(Range1).Select
118: Application.CutCopyMode = False
119: Selection.Copy 120: 121: Sheets("M - C").Select
122: 123: If j = 1 Then
124: C(((C(Rows.Count, 1).End(xlUp).Offset(1, 0).Row)) + 1, 1).Select ' Save the file!
125: Else
126: C(((C(Rows.Count, 1).End(xlUp).Offset(1, 0).Row)), 1).Select ' Save the file!
127: End If
128: 129: ActiveSheet.Paste 130: 131: Sheets("M - Working").Select
132: Range("A2:K2").Select
133: Range(Selection, Selection.End(xlDown)).Select
134: Selection.ClearContents 135: 136: Next j ' j Loop End-------------------
137: 138: Sheets("M - C").Select
139: Range(C(R2, 1), C(R2, 13)).Select
140: Selection.AutoFilter141: ActiveWorkbook.Worksheets("M - C").AutoFilter.Sort.SortFields.Clear
142: ActiveWorkbook.Worksheets("M - C").AutoFilter.Sort.SortFields.Add _
143: Key:=C(R2, 13), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _ 144: :=xlSortNormal145: With ActiveWorkbook.Worksheets("M - C").AutoFilter.Sort
146: .Header = xlYes147: .MatchCase = False
148: .Orientation = xlTopToBottom 149: .SortMethod = xlPinYin 150: .Apply151: End With
152: Range(C(R2, 1), C(R2, 13)).Select
153: Selection.AutoFilter 154: 155: Sheets("M - C").Select
156: R2 = C(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
157: Range(C(R2, 1), C(R2, 11)).Select
158: With Selection.Interior
159: .Pattern = xlSolid 160: .PatternColorIndex = xlAutomatic 161: .ThemeColor = xlThemeColorDark2 162: .TintAndShade = -0.249977111117893 163: .PatternTintAndShade = 0164: End With
165: 166: Sheets("M - C").Select
167: Range("A2").Select
168: 169: R1 = R1 + 1 170: 171: Next i
172: 173: Application.CutCopyMode = Flase174: Workbooks(Filename1).Close savechanges:=False
175: 176: ' A ------------------------------------
177: 178: j = 1 179: 180: R1 = 2 181: Workbooks.Open Filename:=Path1 + Filename3 182: 183: For i = 1 To 10
184: 185: Windows(Filename2).Activate186: Sheets("A").Select
187: C(R1, 2).Select
188: BN = ActiveCell.Text 189: 190: For j = 1 To 3 ' j Loop Start-------------------
191: 192: Windows(Filename3).Activate193: Rows("1:1").Select
194: Selection.AutoFilter195: ActiveSheet.Range("$A$1:$K$33384").AutoFilter Field:=2, Criteria1:=BN
196: ActiveSheet.Range("$A$1:$K$33384").AutoFilter Field:=3, Operator:= _
197: xlFilterValues, Criteria2:=Array(2, Days1(j))198: Range("A2").Select
199: Range(Selection, Selection.End(xlToRight)).Select
200: Range(Selection, Selection.End(xlDown)).Select
201: Selection.Copy 202: Windows(Filename2).Activate203: Sheets("A - Working").Select
204: Range("A2").Select
205: ActiveSheet.Paste206: Application.CutCopyMode = False
207: ActiveWorkbook.Worksheets("A - Working").AutoFilter.Sort.SortFields.Clear
208: ActiveWorkbook.Worksheets("A - Working").AutoFilter.Sort.SortFields.Add Key:= _
209: Range("K1:K131"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption _
210: :=xlSortNormal211: With ActiveWorkbook.Worksheets("A - Working").AutoFilter.Sort
212: .Header = xlYes213: .MatchCase = False
214: .Orientation = xlTopToBottom 215: .SortMethod = xlPinYin 216: .Apply217: End With
218: 219: Range("M1").Select
220: Set Range1 = ActiveCell
221: Range(Range1).Select
222: Application.CutCopyMode = False
223: Selection.Copy 224: 225: Sheets("A - C").Select
226: 227: If j = 1 Then
228: C(((C(Rows.Count, 1).End(xlUp).Offset(1, 0).Row)) + 1, 1).Select ' Save the file!
229: Else
230: C(((C(Rows.Count, 1).End(xlUp).Offset(1, 0).Row)), 1).Select ' Save the file!
231: End If
232: 233: ActiveSheet.Paste 234: 235: Range(C(((C(Rows.Count, 1).End(xlUp).Offset(1, 0).Row)), 1), C(((C(Rows.Count, 1).End(xlUp).Offset(1, 0).Row)), 11)).Select
236: 237: With Selection.Interior
238: .Pattern = xlSolid 239: .PatternColorIndex = xlAutomatic 240: .ThemeColor = xlThemeColorDark2 241: .TintAndShade = -0.249977111117893 242: .PatternTintAndShade = 0243: End With
244: 245: Sheets("A - Working").Select
246: Range("A2:K2").Select
247: Range(Selection, Selection.End(xlDown)).Select
248: Selection.ClearContents 249: 250: Next j ' j Loop End -------------------
251: 252: Sheets("A - C").Select
253: Range(C(R3, 1), C(R3, 13)).Select
254: Selection.AutoFilter255: ActiveWorkbook.Worksheets("A - C").AutoFilter.Sort.SortFields.Clear
256: ActiveWorkbook.Worksheets("A - C").AutoFilter.Sort.SortFields.Add _
257: Key:=C(R3, 13), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _ 258: :=xlSortNormal259: With ActiveWorkbook.Worksheets("A - C").AutoFilter.Sort
260: .Header = xlYes261: .MatchCase = False
262: .Orientation = xlTopToBottom 263: .SortMethod = xlPinYin 264: .Apply265: End With
266: Range(C(R3, 1), C(R3, 13)).Select
267: Selection.AutoFilter 268: 269: Sheets("A - C").Select
270: R3 = C(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
271: Range(C(R3, 1), C(R3, 11)).Select
272: With Selection.Interior
273: .Pattern = xlSolid 274: .PatternColorIndex = xlAutomatic 275: .ThemeColor = xlThemeColorDark2 276: .TintAndShade = -0.249977111117893 277: .PatternTintAndShade = 0278: End With
279: 280: Sheets("A - C").Select
281: Range("A2").Select
282: 283: R1 = R1 + 1 284: 285: Next i
286: 287: Application.CutCopyMode = Flase288: Workbooks(Filename3).Close savechanges:=False
289: 290: Windows(Filename2).Activate291: Sheets("Main Menu").Select
292: Range("A1").Select
293: 294: Application.ScreenUpdating = True
295: 296: End Sub
References:
Join Function
http://www.fabalou.com/Excel/joiningcells.asp
http://www.digdb.com/excel_add_ins/join_merge_tables_lists/
Concatenate Function
http://www.techonthenet.com/excel/formulas/concat.php
http://articles.techrepublic.com.com/5100-10878_11-1059968.html
http://www.ozgrid.com/forum/showthread.php?t=69289
http://answers.yahoo.com/question/index?qid=20090310231438AARmli8
Cells and Range Function
http://www.excel-vba.com/vba-code-2-6-cells-ranges.htm
http://www.eng-tips.com/viewthread.cfm?qid=126163&page=9
http://www.excelforum.com/excel-general/576071-excel-vba-range-variable.html
Loops
http://www.exceltip.com/st/Using_Loops_in_VBA_in_Microsoft_Excel/628.html
http://www.ozgrid.com/VBA/VBALoops.htm
Macros FAQ (useful tips and codes)
http://www.contextures.com/xlfaqMac.html#Empty
http://www.contextures.com/xlfaqApp.html#Unused
IsNA Function
http://www.techonthenet.com/excel/formulas/isna.php
http://www.techonthenet.com/excel/formulas/vlookup.php
http://www.computing.net/answers/office/excel-vlookup-if-question/8556.html
Not Equal Statement
http://www.mrexcel.com/forum/showthread.php?p=1507693
Blank Cells
http://www.mrexcel.com/archive/Dates/1211.html
FAQ
http://www.contextures.com/xlfaqMac.html
-urShadow
No comments:
Post a Comment