user-function not returning any result (newbye)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all!
I'm writing a function with two arguments.
This function is part of a module for the worksheet.
I just can't make it work when inserting it into a spreadsheet cell.

Can you help?

Thanks.
Frisk.


Function Result(Value1 As Double, Value2 As Double) As Byte

Select Case Value2
Case Value2 < (20 / 100)
Result = 1
Case Value2 < (50 / 100)
Result = 2
Case Value2 < (100 / 100)
Result = 3
Case Value2 < (110 / 100)
Result = 4
Case Value2 < (120 / 100)
Result = 5

Case Else

Select Case value1
Case value1 < 20 / 100
Result = 1
Case value1 < 50 / 100
Result = 2
Case value1 < 100 / 100
Result = 3
Case value1 < 110 / 100
Result = 4
Case value1 < 120 / 100
Result = 5

Case Else
Result = 0

End Select

End Select

End Function
 
Frisk,

'Result' is the name of an XL4 Macro function. Change the name of
the function to something else.
 
What does "I just can't make it work" mean?

I suspect you need to lose the variable name between each Case and the
less-than sign, i.e., you should have

Select Case Value2
Case Is < (20 / 100)
Rslt = 1
Case Is < (50 / 100)
Rslt = 2
Note that I replaced Result by Rslt just in case Result is a reserved
word at some level in VBA.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top