Is there any function in VBA as "IsEven"

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
please post your version. Using 2007 I did find an isEven funtion is excel (there for also in VBA).

2003 may not be so lucky.

Code:
Function isEven(var As Double)
var = var / 2
var = Round(var, 1)
If (Right(var, 1) = 5) Then
Even
Else
Odd
End If
End Function

This should handle it.
**WARNING** result is not boolean but mearly string text. so you may need an if to analyze the test in order to use it.
 
Upvote 0
Along the same lines as bolo's.
Code:
Option Explicit
    
Function myIsEven(myCell As Range) As Boolean
Dim dblSum As Double
    dblSum = Application.WorksheetFunction.Sum(myCell)
    
    myIsEven = dblSum Mod 2 = 0
End Function

From my understanding, Mod would produce different results, as my understanding of the worksheet function is that it "trucates" (I think rounds down) where Mod rounds...

Maybe round down the input val on the way in?

Mark
 
Upvote 0
Mod divides X by the number stipulated and if there is no remainder (ie it's a perfect division) then it returns true otherwise it returns false.
 
Upvote 0
<CODE>@Blad Hunter:</CODE>
<CODE></CODE>
<CODE>Sorry, I wasn't clear. I was referring to what the expected results of Mod would be, vs the expected results of the worksheet function ISEVEN.</CODE>
<CODE></CODE>
Mark
 
Upvote 0
<CODE>@Blad Hunter:</CODE>
<CODE></CODE>
<CODE>Sorry, I wasn't clear. I was referring to what the expected results of Mod would be, vs the expected results of the worksheet function ISEVEN.</CODE>
<CODE></CODE>
Mark

Yeah I figured that but wanted to explain how it works for the OP, Sorry I should have directed it at the OP in my post :).
 
Upvote 0
myIsEven(-1.5) returns TRUE, ISEVEN(-1.5) returns False.

You could use
Code:
Function VBAIsEven(inputVal As Double) As Boolean
    VBAIsEven = Evaluate("ISEVEN(" & CStr(inputVal) & ")")
End Function
 
Upvote 0
Mod divides X by the number stipulated and if there is no remainder (ie it's a perfect division) then it returns true otherwise it returns false.

Actually I have written this wrong. When used in that context it will return true or false. The mod command itself will return the number remaining after all whole occurences of the value have been removed.

13 mod 4 would be 1 as 1 is the remainder after the highest whole multiple of 4 (12) is removed from the original number.
 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,113,998
Members
448,539
Latest member
alex78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top