VBA Sheet transfer 'Overflow'

JBGH

New Member
Joined
Apr 15, 2011
Messages
3
Hello everyone. First time post. I'm having trouble with VBA and the error that appears is 'Run-time error '6': Overflow. The place in the code that it highlights is in red below with commentary.

Basically what this sheet is doing is taking production history from oil wells and organizing it from a 'datadump' type format listed down thousands of rows and putting it on a new sheet in a column format (each well gets a column) - it also normalizes the data a bit if a well produced less than a certain amt each day / change month over month was abnormal, etc. I expanded the 'activate cells' part on the destination sheet b/c there is more history this time around (obv. more months of data each time we update), but it's still giving me this error.

I took over this sheet at work and all I did was add extra data (more months of production), so not sure why it isn't working. Added in the same format, etc.

Any help would be greatly appreciated.


Sub ProductionPop()


Dim API As String
Dim shSource As Worksheet
Dim shDest As Worksheet
Dim x As Long
Dim Y As Long
Dim m As Long
Dim BBLD As Integer
Dim MCFD As Integer
Dim PriorBBLD As Integer
Dim Prior2BBLD As Integer
Dim PriorMCFD As Integer
Dim DaysOn As Integer




Set shSource = ThisWorkbook.Sheets("Monthly Production") 'note: cannot change sheet name
Set shDest = ThisWorkbook.Sheets("Production") 'note: cannot change sheet name


Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual


Y = 2
x = 2


shDest.Activate
Columns("C:WWW").Select
Selection.Delete Shift:=xlToLeft
Range("B2").Select
Selection.ClearContents
Range("B10:B84").Select
Selection.ClearContents


Do
m = 10
API = shSource.Cells(Y, 6)
shDest.Cells(2, x) = API


Do
BBLD = shSource.Cells(Y, 16)
MCFD = shSource.Cells(Y, 17) (This is where my error is happening- When I hold the cursor over it it says 'Shsheet.cells(Y,17)=137600' - I went to the 137,600th row and there is nothing abnormal about the data there.... not sure why this is happening? It's pulling both oil and gas production but showing an error for the gas and not the oil.. totally confused on this...
'Debug.Print BBLD
If BBLD < 10 Then GoTo nextmonth 'excludes production less than 10bbld
DaysOn = shSource.Cells(Y, 15)
If DaysOn < 8 Then GoTo nextmonth 'excludes montly production with less than 8 days on production

If m = 10 Then GoTo Operation

PriorBBLD = shDest.Cells(m - 1, x)
'Debug.Print PriorBBLD
If BBLD / PriorBBLD < 0.25 Then GoTo nextmonth '75% drop in MoM production considered well issue for month
If BBLD / PriorBBLD > 1.25 And m <= 12 Then 'Current month MoM production increase over 1.25x, prior month production considered well issue, overwrites previous month (first two months only)
'Debug.Print BBLD / PriorBBLD
m = m - 1
GoTo Operation
End If
If BBLD / PriorBBLD > 1.66 And m <= 24 And m > 12 Then 'Current month MoM production increase over 1.66x, prior month production considered well issue, overwrites previous month (first year only)
'Debug.Print BBLD / PriorBBLD
m = m - 1
GoTo Operation
End If
If BBLD / PriorBBLD > 2 And BBLD > 30 And m > 24 Then m = m - 1 'Current month MoM production increase over 2x, prior month production considered well issue, overwrites previous month (after first year)

Operation:
shDest.Cells(m, x) = BBLD
shDest.Cells(m, x + 1) = MCFD
m = m + 1

If m = 12 Then
Prior2BBLD = shDest.Cells(m - 2, x)
If BBLD / Prior2BBLD > 1.35 Then
shDest.Cells(m - 2, x) = BBLD
m = m - 1
End If
End If




nextmonth:


Y = Y + 1
Loop While shSource.Cells(Y, 6) = shSource.Cells(Y - 1, 6)

shDest.Cells(3, x + 2).FormulaR1C1 = shDest.Cells(3, x).FormulaR1C1
shDest.Cells(4, x + 2).FormulaR1C1 = shDest.Cells(4, x).FormulaR1C1
shDest.Cells(5, x + 2).FormulaR1C1 = shDest.Cells(5, x).FormulaR1C1
shDest.Cells(6, x + 2).FormulaR1C1 = shDest.Cells(6, x).FormulaR1C1
shDest.Cells(7, x + 2).FormulaR1C1 = shDest.Cells(7, x).FormulaR1C1

shDest.Cells(60, x + 2).FormulaR1C1 = shDest.Cells(60, x).FormulaR1C1
shDest.Cells(61, x + 2).FormulaR1C1 = shDest.Cells(61, x).FormulaR1C1
shDest.Cells(62, x + 2).FormulaR1C1 = shDest.Cells(62, x).FormulaR1C1
shDest.Cells(63, x + 2).FormulaR1C1 = shDest.Cells(63, x).FormulaR1C1
shDest.Cells(64, x + 2).FormulaR1C1 = shDest.Cells(64, x).FormulaR1C1

x = x + 2

'If x = 960 Then k = x / 0

API = shSource.Cells(Y, 6)


Loop Until API = ""


Application.Calculation = xlCalculationAutomatic


End Sub


'Run-time error '6':

Overflow
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
you have BBLD As Integer, (and others)
Try changing ALL integers to LONG. Overflow is a hint to this, but try it anyway.
 
Upvote 0

Forum statistics

Threads
1,216,571
Messages
6,131,482
Members
449,653
Latest member
aurelius33

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