How to reply a TRUE/False via VBA

  • Thread starter Thread starter FARAZ QURESHI
  • Start date Start date
F

FARAZ QURESHI

How to develop a simple UDF like:
=Correct(Salary,Tax)
so as to return a TRUE if the argument Tax = Salary * 10%?
Thanx!
 
Insert a module to the VBA project and use code like:

Function Correct(Salary As Double, Tax As Double) As Boolean
If Abs(Tax - (Salary * 0.1)) < 0.001 Then
Correct = True
Else
Correct = False
End If
End Function

The function considers a difference between Tax and Salary * 10% of
less than 0.001 to mean equal. Due to the intrinsic rounding, it is
likely that the two values may be slightly different when they should,
in fact, be considered equal.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
Function Correct(Salary,Tax)
if Tax = (.1 * Salary ) then
Correct = True
else
Correct = False
end if
End Function
 
Function Correct(Salary As Double, Tax As Double) As Boolean
Correct = Abs(Tax - (Salary * 0.1)) < 0.001
End Function
 

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