Why is this summation not working?

Petroleum_Engineer

New Member
Joined
Aug 6, 2016
Messages
5
Hi All,

So i have run into a problem that I cant seem to solve. Here is the code in question:

Dim YY As Long
Dim ZZ As Long


YY = 0
ZZ = 0

For j = 2 To MaxRow


If InStr(1, ActiveSheet.Cells(j, 2), "End:") <> 0 And ActiveSheet.Cells(j, 32) < 0 Then
ActiveSheet.Cells(j, 32).Interior.ColorIndex = 3
End If

If InStr(1, ActiveSheet.Cells(j, 2), "End:") <> 0 And ActiveSheet.Cells(j, 32) < 0 Then
Worksheets("Blah").Cells(kk, 1) = ActiveSheet.Cells(j, 2).Value
kk = kk + 1
End If

'Final Summations

If InStr(1, ActiveSheet.Cells(j, 2), "End:") <> 0 And ActiveSheet.Cells(j, 32) < 0 Then
YY = YY + ActiveSheet.Cells(j, 31).Value
End If

If InStr(1, ActiveSheet.Cells(j, 2), "End:") <> 0 And ActiveSheet.Cells(j, 32) < 0 Then
ZZ = ZZ + ActiveSheet.Cells(j, 32).Value
End If


Next j


ActiveSheet.Cells(MaxRow + 1, 31) = YY
ActiveSheet.Cells(MaxRow + 2, 31).WrapText = True
ActiveSheet.Cells(MaxRow + 2, 31) = "Monthly Fixed Cost Associated w/ Uneconomic Wells (Excluding Ad Valorem & COPAS)"
ActiveSheet.Cells(MaxRow + 1, 31).Font.Bold = True
ActiveSheet.Cells(MaxRow + 1, 31).Borders(xlDiagonalDown).LineStyle = xlNone
ActiveSheet.Cells(MaxRow + 1, 31).Borders(xlDiagonalUp).LineStyle = xlNone
ActiveSheet.Cells(MaxRow + 1, 31).Borders(xlEdgeRight).LineStyle = xlNone
ActiveSheet.Cells(MaxRow + 1, 31).Borders(xlInsideVertical).LineStyle = xlNone
ActiveSheet.Cells(MaxRow + 1, 31).Borders(xlInsideHorizontal).LineStyle = xlNone
ActiveSheet.Cells(MaxRow + 1, 31).Borders(xlEdgeLeft).LineStyle = xlNone
ActiveSheet.Cells(MaxRow + 1, 31).Borders(xlEdgeBottom).LineStyle = xlNone
With ActiveSheet.Cells(MaxRow + 1, 31).Borders(xlEdgeTop)
.LineStyle = xlDashDotDot
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With


ActiveSheet.Cells(MaxRow + 1, 32) = ZZ
ActiveSheet.Cells(MaxRow + 2, 32).WrapText = True
ActiveSheet.Cells(MaxRow + 2, 32) = "Monthly Cost to Operate Uneconomic Wells"
ActiveSheet.Cells(MaxRow + 1, 32).Font.Bold = True
ActiveSheet.Cells(MaxRow + 2, 32).VerticalAlignment = xlCenter
ActiveSheet.Cells(MaxRow + 1, 32).Borders(xlDiagonalDown).LineStyle = xlNone
ActiveSheet.Cells(MaxRow + 1, 32).Borders(xlDiagonalUp).LineStyle = xlNone
ActiveSheet.Cells(MaxRow + 1, 32).Borders(xlEdgeRight).LineStyle = xlNone
ActiveSheet.Cells(MaxRow + 1, 32).Borders(xlInsideVertical).LineStyle = xlNone
ActiveSheet.Cells(MaxRow + 1, 32).Borders(xlInsideHorizontal).LineStyle = xlNone
ActiveSheet.Cells(MaxRow + 1, 32).Borders(xlEdgeLeft).LineStyle = xlNone
ActiveSheet.Cells(MaxRow + 1, 32).Borders(xlEdgeBottom).LineStyle = xlNone
With ActiveSheet.Cells(MaxRow + 1, 32).Borders(xlEdgeTop)
.LineStyle = xlDashDotDot
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With


ActiveSheet.Rows(MaxRow + 2).RowHeight = 60


What bothers me is the Sub runs perfectly fine and the summation for variable "ZZ" is working correctly but the one for "YY" is not. Any ideas/ need more info?

Thanks!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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