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!
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!