VBA Troubleshooting

Dec 9th, 2015
SKTFaker
Category:
Programming
Price: $70 USD

Question description

I need someone to trouble shoot this code. The button needs to be automated. I think the idea of the button is to initiate the code with one click. There are also some problems with the code and it doesn't run. If someone could help troubleshoot that it would be appreciated 

 PLEASE ask me if there is anything unclear in the code or anything like that. I realize it's a little complicated since it's for a drilling engineering class but I can clarify if need be. Ask and I will get back to you within an hour

Code is pasted below. I will email my spreadsheet once I am set on a tutor

------------

Option Explicit

Function log10(x As Double) As Double

log10 = log(x) / log(10)

End Function

Function PLossInside_f(Q As Double, ID As Double) As Double

    Dim MW As Double, A As Double, B As Double, C As Double

    MW = Worksheets("Mud Data").Cells(2, 2).Value

    A = Worksheets("Mud Data").Cells(5, 6).Value

    B = Worksheets("Mud Data").Cells(6, 6).Value

    C = Worksheets("Mud Data").Cells(7, 6).Value

    Dim n As Double, R As Double, T_guess As Double, K_v As Double, x As Double

    Dim delP As Double, T_new As Double, Tol As Double

    Dim f_p As Double, k_p As Double

    Dim v As Double, N_p As Double, AA As Double, L As Double, BB As Double, Y As Double, fric As Double

    Dim diff As Double, i As Integer, h As Double, k As Double

   

    R = 25

    n = B + 2 * C * log(R)

    T_guess = Exp(A + B * log(R) + C * log(R) ^ 2)

    Tol = 0.0005

    diff = 1

    i = 1

Do While (diff > Tol) And (i < 30)

    h = 1 / (2 * C)

    k = ((B ^ 2) + (4 * C) * (log(T_guess) - A)) ^ (1 / 2)

    R = Exp(h * ((-B)  k))

    n = B + 2 * C * log(R)

    x = (0.123 / n) / (1 - (1.0678) ^ ((-2) / n))

    K_v = 0.01066 * T_guess / (1.703 * R) ^ n

    f_p = ((3 * n + 1) / (4 * n * x)) ^ n

    k_p = f_p * K_v

    v = Q / (2.45 * (ID ^ 2))

    N_p = (1.86 / k_p) * ((ID / 96) ^ n) * (v ^ (2 - n)) * MW

    AA = (log10(n) + 3.93) / 50

    L = 3470 - 1370 * n

    BB = (1.75 - log10(n)) / 7

    Y = 4270 - 1370 * n

   

    If (N_p <= L) Then

        fric = 16 / N_p

        'Shows laminar flow regime

    ElseIf (N_p >= Y) Then

        fric = AA / N_p ^ BB

        'Shows turbulent flow regime

    Else

        fric = ((N_p - L) / 800) * (AA / Y ^ BB - 16 / L) + 16 / L

    End If

    delP = (fric * MW * v ^ 2) / (25.8 * ID)

    T_new = 281.4 * delP * ID

    diff = Abs(T_new - T_guess)

    T_guess = T_new

    i = 1 + i

Loop

PLossInside_f = delP

End Function

Function PLossAnnular_f(Q As Double, OD As Double, HD As Double) As Double

    Dim MW As Double, A As Double, B As Double, C As Double

    MW = Worksheets("Mud Data").Cells(2, 2).Value

    A = Worksheets("Mud Data").Cells(5, 6).Value

    B = Worksheets("Mud Data").Cells(6, 6).Value

    C = Worksheets("Mud Data").Cells(7, 6).Value

    Dim n As Double, R As Double, T_guess As Double, K_v As Double, x As Double, T_new As Double, Tol As Double

    Dim v As Double, N_a As Double, AA As Double, BB As Double, L As Double, Y As Double, delP As Double

    Dim fric As Double, diff As Double, i As Integer, h As Double, k As Double, f_a As Double, k_a As Double

   

    R = 25

    n = B + 2 * C * log(R)

    T_guess = Exp(A + B * log(R) + C * log(R) ^ 2)

    Tol = 0.0005

    diff = 1

    i = 1

Do While (diff > Tol) And (i < 30)

    h = 1 / (2 * C)

    k = ((B ^ 2) + (4 * C) * (log(T_guess) - A)) ^ (1 / 2)

    R = Exp(h * ((-B) + k))

    n = B + 2 * C * log(R)

    x = (0.123 / n) / (1 - (1.0678) ^ ((-2) / n))

    K_v = 0.01066 * T_guess / (1.703 * R) ^ n

    f_a = ((2 * n + 1) / (3 * n * x)) ^ n

    k_a = f_a * K_v

    v = Q / (2.45 * (HD ^ 2 - OD ^ 2))

    N_a = (2.79 / k_a) * (((HD - OD) / 144) ^ n) * (v ^ (2 - n)) * MW

    AA = (log10(n) + 3.93) / 50

    L = 3470 - 1370 * n

    BB = (1.75 - log10(n)) / 7

    Y = 4270 - 1370 * n

   

    If (N_a <= L) Then

        fric = 24 / N_a

        'shows laminar flow regime

    ElseIf (N_a >= Y) Then

        fric = AA / N_a ^ BB

        'shows turbulent flow regime

    Else

        fric = ((N_a - L) / 800) * (AA / Y ^ BB - 24 / L) + 24 / L

    End If

    delP = (fric * MW * v ^ 2) / (25.8 * (HD - OD))

    T_new = 281.4 * (HD - OD) * delP

    diff = Abs(T_new - T_guess)

    T_guess = T_new

    i = 1 + i

Loop

PLossAnnular_f = delP

End Function


amery_311project3.xlsm

Tutor Answer

(Top Tutor) Daniel C.
(997)
School: UIUC
PREMIUM TUTOR

Studypool has helped 1,244,100 students

7 Reviews


Summary
Quality
Communication
On Time
Value
kpcutie
Nov 29th, 2016
" Excellent job "
Hemapathy
Nov 15th, 2016
" all I can say is wow very fast work, great work thanks "
BlueOcean
Nov 2nd, 2016
" Awesome! Exactly what I wanted. "
kevin12622
Oct 24th, 2016
" Goes above and beyond expectations ! "
ashleyisgod
Oct 10th, 2016
" Top quality work from this guy! I'll be back! "
likeplum4
Oct 1st, 2016
" Excellent work as usual "
Molly_Moon
Sep 18th, 2016
" AMAZING as always! "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1826 tutors are online

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors