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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting Even numbers??

Status
Not open for further replies.

JONBOY74

Technical User
Sep 11, 2001
36
0
0
US
Morning All

In Excel you can use the following to return a true or False statement if a number is EVEN or not:

=IsEven(3) - this returns False

How can I do the same thing in code. I'm trying to use it within a Select Case or If statement. For Example:

Select case !VersionNo

case isEven

case isOdd

end select


Can Anyone help

Thanks

Jon
 
I think you may get a great many solutions to this one but here's one option

Code:
Sub tract()
Dim c
For Each c In ActiveSheet.UsedRange.Cells
    If c.Value Mod 2 = 0 Then
        c.Font.Bold = True
    Else: c.Font.Bold = False
    End If
Next
End Sub

;-) If a man says something and there are no women there to hear him, is he still wrong?
 
If you are just evaluating even or odd, why not just use a boolean variable which will evaluate to true or false:

Sub testnums()
Dim IsEven As Boolean
If Int([a1] / 2) = [a1] / 2 Then
IsEven = True
Else
IsEven = False
End If
MsgBox IsEven
End Sub Rgds
~Geoff~
 
Hi,

You could also use

Application.WorksheetFunction.Even(value)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top