Thread: Excel Troubles
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
DavidC[_2_] DavidC[_2_] is offline
external usenet poster
 
Posts: 44
Default Excel Troubles

Forgot to remind you to add in the constant. So try the
routine from medialint as revised below to fix the natural
log problem and the negative value issue and add in the
constant. I have referenced cell C1 for the constant to
make it easier for the constant to be changed without
going to the routine. Also if you want, add Msgbox
(myrandomnum) after the Loop statement to give you the
answer quickly without having to search for it.


Sub LoopSolve()
Randomize
Dim myRandomNum As Single
Dim YRow As Long
Dim XAdd As Long
Dim CalcDiff As Single
YRow = 2
Worksheets("Sheet1").Cells(1, 1) = "Number"
Worksheets("Sheet1").Cells(1, 2) = "Difference"
con = ActiveSheet.Range("C1").Value

Do
myRandomNum = Rnd * 100
CalcDiff = Abs(1 / (myRandomNum ^ 0.5)) - (2 *
con * (Log(myRandomNum ^ 0.5) / Log(10#)) - 0.8)
Worksheets("Sheet1").Cells(YRow, 1 + XAdd) =
myRandomNum
Worksheets("Sheet1").Cells(YRow, 2 + XAdd) =
CalcDiff
YRow = YRow + 1
If YRow 65536 Then
YRow = 2
XAdd = XAdd + 2
End If
Loop Until CalcDiff < 0.001 And CalcDiff -0.001

End Sub

Best of luck

DavidC
-----Original Message-----
I have a equation that you can solve only by trial an

error, but I want
excel to do the work for me. The equation is this

1/(X^.5)=2Log(C*X^.5)-.8
Where c is some constant that isant worth mentioning ;)
and the Log is base 10.
Ok I need a macro that will keep trying values untill one

side is equal
to the other up to .001 decimal places. I tried making

some sort of
random function generator, but it seems like the random

function kept
repeating certain values. Any advice/help is appericated.
-Mark


---
Message posted from http://www.ExcelForum.com/

.