Logical test as a variable in a UDF

G

Guest

Hello - Is it possible to pass a logical test through a variable? For example:

function testFunc(A as integer, test as String, B as integer)
if (A test B) then
testFunc = "A is greater than B"
else:
testFunc = "A is not greater than B"
end if
end function


And entered like so in the spreadsheet:

=test(2,">",1)
 
D

Dave Peterson

Maybe...

Option Explicit
Function testFunc(A As Integer, test As String, B As Integer)
testFunc = Application.Evaluate(A & test & B)
End Function
Sub testme()
MsgBox testFunc(2, ">", 1)
End Sub
 
G

Guest

Worked perfect, thanks!

Dave Peterson said:
Maybe...

Option Explicit
Function testFunc(A As Integer, test As String, B As Integer)
testFunc = Application.Evaluate(A & test & B)
End Function
Sub testme()
MsgBox testFunc(2, ">", 1)
End Sub
 

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

Top