PyroJoe84

I'm writing a program to do some basic design for wood stud walls. The actual process really isn't important, but there is a part I am having problems with.

The process involves many different equations and I need to end up solving for the total load, P. However, when all the equations needed are combined together (needs to be <= 1.0), 'P' occurs multiple times and is nearly immpossible to isolate and solve for.

My next thought then is to just run a loop and plug in an initial guess for P (Pi) and compare the value to 1.0. After comparing it, the loop would then adjust it and calculate the new value and compare that to 1.0 and then adjust that, and so on.

However, when I run the code, it comes up with an error of "Type mismatch." I have delcared all variables in question and have removed the type from each variable thus making them all of type "variant." Yet, still I get the "Type mismatch."

I'm not sure what else to do, so please review the code below and let me know what you think I should be doing.

*I am definitely an amateur at VBA, I just started teaching myself last week, so be prepared for code that may be able to be simplified.

Thank you to all those that can help!

<<

Public Sub SolveForP()

'Do loop will repeat until the difference of the given value (1.0) and the calculated value (X)

'is less than 0.01

Do

fc1 = Pi / (d * b)

X = (fc1 / Fprimec1) ^ 2 + (fb / (Fb2(1 - (fc1 / FcE))))

Pdesign = Pi

Pi = Pi / X

Loop Until Abs(X - 1) <= 0.01

Worksheets("Main").Range("B21").Value = fc1

Worksheets("Main").Range("B32:C32").Value = Pdesign

End Sub

>>

Please let me know if any code may be missing. I did not include the entire code (i.e. variable declarations, sheet formatting code, etc.)