Coding

E

Ed

What would be the code in a macro to accomplish the following:


If the (maximum of cell range A5 thru A9) is greater than the
(average of cells A5 thru A9) times 1.05 or if the (minimum of cell
range A5 thru A9) is less than the (average of cell A5 thru A9) times
0.95 then A10 equals "Fail" else A10 = "Pass"


Some time back I got information on a similar problem, but I had a
computer crash and I lost it.

Any help would be appreciated.


Ed English
 
M

Mike H

Hi,

If I've iunderstood correctly, try this

Dim MyRange As Range
Set MyRange = Range("A5:A9")
If WorksheetFunction.Max(MyRange) > WorksheetFunction.Average(MyRange) *
1.05 Or _
WorksheetFunction.Min(MyRange) < WorksheetFunction.Average(MyRange) * 0.05
Then
Range("A10").Value = "Fail"
Else
Range("A10").Value = "Pass"
End If

Mike
 
M

Mike H

Typo,

Try this instead

Dim MyRange As Range
Set MyRange = Range("A5:A9")
If WorksheetFunction.Max(MyRange) > WorksheetFunction.Average(MyRange) *
1.05 Or _
WorksheetFunction.Min(MyRange) < WorksheetFunction.Average(MyRange) * 0.95
Then
Range("A10").Value = "Fail"
Else
Range("A10").Value = "Pass"
End If

Mike
 
E

Ed

Mike,

Tried both and got compile error. will review and advise.

Thanks for replies.


Ed English
 
E

Ed

It is a syntax error


Typo,

Try this instead

Dim MyRange As Range
Set MyRange = Range("A5:A9")
If WorksheetFunction.Max(MyRange) > WorksheetFunction.Average(MyRange) *
1.05 Or _
WorksheetFunction.Min(MyRange) < WorksheetFunction.Average(MyRange) * 0.95
Then
Range("A10").Value = "Fail"
Else
Range("A10").Value = "Pass"
End If

Mike
 
M

Mike H

Ed,

The syntax error is caused by the post line-wrapping.

This is all one line

If WorksheetFunction.Max(MyRange) > WorksheetFunction.Average(MyRange) *
1.05 Or _

Mike
 
Top