Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Why math functions do not work?

  Asked By: Brayden    Date: Nov 06    Category: MS Office    Views: 1085
  

I got weird problem and need help:(
I worte VBA as following;

(Sub xformula()
dim i,k, q as double
q = Worksheets("input").Range("e12").Value
For i = 1 To q
k = Worksheets("input").Cells(14 + i, 6).Value
Cells(11 + i, 7).Value = 1 + (MAx(Cells(11 + i, 5).Value, 0.2) - 1) / Sqrt(k)
Next i
End Sub)

But the MAX and Sqrt functions do not work here. the system gave me error,
please help! Thanks!

Share: 

 

6 Answers Found

 
Answer #1    Answered By: Volney Fischer     Answered On: Nov 06

MAX and SQRT are worksheet functions, not VBA functions. Some worksheet
functions can be used in your VBA code, if you specify them as
Application.WorksheetFunction.FUNCTION, where FUNCTION is one of the available
worksheet functions. With this change, your code looks like this:

Sub xformula()
Dim i As Double, k As Double, q As Double
q = Worksheets("input").Range("e12").Value
For i = 1 To q
k = Worksheets("input").Cells(14 + i, 6).Value
Cells(11 + i, 7).Value = 1 + (Application.WorksheetFunction.Max(Cells(11
+ i, 5).Value, 0.2) - 1) / Application.WorksheetFunction.Sqrt(k)
Next i
End Sub

I haven't tested this, but it compiles correctly. Also, SQRT() applied to to
negative number will generate an error.

 
Answer #2    Answered By: Sophie Campbell     Answered On: Nov 06

I tried, the Max function did work. but it seems the SQRT doesn't belong to
worksheetfunction and it didn't work. Are there anyway to use SQRT function?

 
Answer #3    Answered By: Adalwine Fischer     Answered On: Nov 06

You can use the POWER function, which does belong to worksheetfunction, as
follows:

Application.WorksheetFunction.Power(k, 0.5)

This returns the square root of k.

 
Answer #4    Answered By: Kristin Johnston     Answered On: Nov 06

Try k = val(Worksheets("input").Cells(14 + i, 6).Value)

 
Answer #5    Answered By: Beatriz Silva     Answered On: Nov 06

I tried. but it gave me same error  :(

 
Answer #6    Answered By: Yvonne Watkins     Answered On: Nov 06

The vba  equivalent of the workshet function SQRT is SQR so
......./Sqr(k)
might work.

 
Didn't find what you were looking for? Find more on Why math functions do not work? Or get search suggestion and latest updates.




Tagged: