Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Possible to store and use a comparison operator in a variable?

Status
Not open for further replies.

axel67

Technical User
Jan 2, 2007
21
Hi,
Does anyone know if it is possible to store comparison operators like "<=" in a variable and use them later in a comparison statement?

Example:
Function CellCompare(FirstCell As Range, SecondCell As Range, CompareOperator As Range)
'compare operator can be "=", "<>", "<=",.....

CellCompare = (FirstCell.Value & CompareOperator.Value & SecondCell.Value)
'should return true of false dpending if condition is met

End Function


This breaks my head for some hours now. Thanks for any hints.
Cheers,
Axel
 
How about

Code:
Function CellCompare(cell1, cell2, operator)
CellCompare = Evaluate(cel1 & operator & cel2)
End Function

Fen
 
dammit - typos

Code:
Function CellCompare(cell1, cell2, operator)
CellCompare = Evaluate(cel[COLOR=red][b]l[/b][/color]1 & operator & cel[COLOR=red][b]l[/b][/color]2)
End Function
 
Thanks to all!
This works great for numeric expression (my main purpose). I will have a look with the evaluate function, if it is possible to do also a textual comparison.

Cheers,
Axel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top