-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatemp.py
159 lines (97 loc) · 4.71 KB
/
atemp.py
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
Sub Button1_Click()
Dim counterLeft, counterRight, counterReport, LeftAccumulator, RightAccumulator As Integer
Dim MaxLimit As Integer
MaxLimit = Cells(2, 11).Value
counterLeft = 2
counterRight = 2
counterReport = 2
AccumulateLeft = True
AccumulateRight = True
LeftContentsIsOver = False
RightContentsIsOver = False
LeftAccumulator = 0
RightAccumulator = 0
'MsgBox (StrComp(Cells(counterLeft, 2).Value, "", vbTextCompare) <> 0)
'MsgBox (Cells(counterLeft, 2).Value)
'MsgBox ("-" + Cells(4, 5).Value + "-")
'MsgBox (StrComp(Cells(4, 5).Value, "", vbTextCompare = 0))
Range(Cells(2, 8), Cells(30000, 9)).Clear
While ( _
(StrComp(Cells(counterLeft, 2).Value, "", vbTextCompare) <> 0) Or _
(StrComp(Cells(counterRight, 5).Value, "", vbTextCompare) <> 0)) _
And _
(counterLeft < MaxLimit) And _
(counterRight < MaxLimit)
If AccumulateLeft Then
LeftAccumulator = Cells(counterLeft, 3).Value
While (Cells(counterLeft, 2).Value = Cells(counterLeft + 1, 2).Value) And _
(StrComp(Cells(counterLeft, 2).Value, "", vbTextCompare) <> 0)
LeftAccumulator = LeftAccumulator + Cells(counterLeft + 1, 3).Value
counterLeft = counterLeft + 1
Wend
AccumulateLeft = False
End If
If AccumulateRight Then
RightAccumulator = Cells(counterRight, 6).Value
While ((Cells(counterRight, 5).Value = Cells(counterRight + 1, 5).Value) And _
(StrComp(Cells(counterRight, 5).Value, "", vbTextCompare) <> 0))
RightAccumulator = RightAccumulator + Cells(counterRight + 1, 6).Value
counterRight = counterRight + 1
Wend
AccumulateRight = False
End If
'''Compare
If Cells(counterLeft, 2).Value = Cells(counterRight, 5).Value Then
Cells(counterReport, 8).Value = Cells(counterLeft, 2).Value
Cells(counterReport, 9).Value = RightAccumulator - LeftAccumulator
counterReport = counterReport + 1
counterLeft = counterLeft + 1
counterRight = counterRight + 1
If StrComp(Cells(counterLeft, 2).Value, "", vbTextCompare) = 0 Then
LeftContentsIsOver = True
Else
AccumulateLeft = True
End If
If StrComp(Cells(counterRight, 5).Value, "", vbTextCompare) = 0 Then
RightContentsIsOver = True
Else
AccumulateRight = True
End If
Else
If ((Cells(counterLeft, 2).Value < Cells(counterRight, 5).Value) And _
StrComp(Cells(counterLeft, 2).Value, "", vbTextCompare) <> 0) _
Or _
RightContentsIsOver Then
Cells(counterReport, 8).Value = Cells(counterLeft, 2).Value
Cells(counterReport, 9).Value = -1 * LeftAccumulator
counterReport = counterReport + 1
counterLeft = counterLeft + 1
If StrComp(Cells(counterLeft, 2).Value, "", vbTextCompare) = 0 Then
LeftContentsIsOver = True
Else
AccumulateLeft = True
End If
Else
If (Cells(counterLeft, 2).Value > Cells(counterRight, 5).Value And _
StrComp(Cells(counterLeft, 2).Value, "", vbTextCompare) <> 0) Or _
LeftContentsIsOver Then
Cells(counterReport, 8).Value = Cells(counterRight, 5).Value
Cells(counterReport, 9).Value = RightAccumulator
counterReport = counterReport + 1
counterRight = counterRight + 1
' MsgBox (StrComp(Cells(counterRight, 5).Value, "", vbTextCompare = 0))
If StrComp(Cells(counterRight, 5).Value, "", vbTextCompare) = 0 Then
RightContentsIsOver = True
Else
AccumulateRight = True
End If
End If
End If
End If
Wend
If (counterLeft >= MaxLimit) Or (counterRight >= MaxLimit) Then
MsgBox ("Error: No 'X' was provided at end of the list. Try again")
Else
MsgBox ("Completed")
End If
End Sub