I can't seem to find where the type mismatch occurs. Any ideas?
Code:
Sub CalculateAndPlot_Click()
Dim AxialForce As Double
Dim CTWeight As Double
Dim FormationFrictionConstant As Double
Dim CasingDepth As Double
Dim CasingFrictionConstant As Double
Dim WellDepth As Double
Dim HoldAngle As Double
Dim KOP As Integer
Dim Build As Double
Dim Interval As Integer
Dim RowsForClearing As Integer
Dim WellboreFluidDensity As Double
Dim InitWellOrientation As Double
Dim theta As Double
Dim r1 As Double
Dim n As Integer
Dim i As Integer
Dim j As Integer
'This is in lb-f
AxialForce = Cells(4, 3).Value
'This is in lb/ft
CTWeight = Cells(5, 3).Value
'This is unitless
FormationFrictionConstant = Cells(7, 3).Value
'This is in ft
CasingDepth = Cells(8, 3).Value
CasingFrictionConstant = Cells(9, 3).Value
'This is in ft
WellDepth = Cells(10, 3).Value
'This is in ft
Interval = Cells(4, 13).Value
'This is in rows
RowsForClearing = Cells(5, 13).Value
'This is in lb/gal
WellboreFluidDensity = Cells(12, 3).Value
'This is in degrees. We convert to radians.
InitWellOrientation = (Cells(14, 3).Value / 180) * 3.14
'This is in ft
KOP = Cells(15, 3).Value
'This is in deg/100ft.
Build = Cells(16, 3).Value / 100
'This is in deg. We convert to radians.
HoldAngle = Cells(17, 3).Value
n = WellDepth / Interval
'clear contents of old calculations and of all formatting.
For i = 1 To (RowsForClearing)
Cells(5 + i, 6).ClearContents
Cells(5 + i, 7).ClearContents
Cells(5 + i, 8).ClearContents
Cells(5 + i, 9).ClearContents
Cells(5 + i, 10).ClearContents
Cells(5 + i, 7).Select
Selection.Style = "Normal"
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
End With
Cells(5 + i, 8).Select
Selection.Style = "Normal"
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
End With
Next i
'format the input cells for well orientation.
For i = 0 To (n)
Cells(6 + i, 7).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
Cells(6 + i, 8).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
Cells(6 + i, 9).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
Cells(6 + i, 6).Value = i * Interval
Next i
r1 = (180 / 3.14) * (1 / Build)
Cells(6, 7).Value = Round(InitWellOrientation * 180 / 3.14, 1)
For i = 1 To WellDepth
'Enter initial wellbore orientation for all sections shallower than the KOP
If i < (KOP + 1) Then
If i Mod Interval = 0 Then
theta = InitWellOrientation * 180 / 3.14
j = i / Interval
Cells(6 + j, 7).Value = Round(theta, 1)
End If
'For all measured depths past the KOP...
ElseIf i >= (KOP + 1) Then
'Only do the calculations if it is a depth that is an output
If i Mod Interval = 0 Then
theta = (i - CDbl(KOP)) * 180 / 3.14 / CDbl(r1) + (InitWellOrientation * 180 / 3.14)
End If
'Ensure the max angle is the HoldAngle
If theta > HoldAngle Then
theta = HoldAngle
End If
'Output theta
j = i / Interval
Cells(6 + j, 7).Value = Round(theta, 1)
End If
Next i
End Sub