How is ISODD and ISEVEN function used in VBA?

Dick Mezzanotte 20 Reputation points
2025-05-20T14:03:22.8033333+00:00

the ISEVEN ISODD functions are supported in spreadsheet formulas but how are they used in VBA code?

I get an error message indication the function is not defined..

Developer technologies VB
{count} votes

Accepted answer
  1. Saideep Anchuri 9,425 Reputation points Microsoft External Staff Moderator
    2025-05-28T15:16:46.8966667+00:00

    Hi Dick Mezzanotte

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer.

    Ask: How is ISODD and ISEVEN function used in VBA?

    Solution: The issue is resolved. here is how you solved your issue:

    Sub MacroTest()

    Dim R_owe As Variant

    Dim cur_row As Integer

    Dim Val As Double

    Dim ans As String

    R_owe = 2

    While R_owe < 15

    If (WorksheetFunction.IsEven(Range(Cells(R_owe, 7), Cells(R_owe, 7)).Value)) _
    
      Then
    
        ans = "EVEN"
    
      Else
    
        ans = "Odd"
    
    End If
    
    Range(Cells(R_owe, 9), Cells(R_owe, 9)) = ans
    
    R_owe = R_owe + 1
    

    If I missed anything please let me know and I'd be happy to add it to my answer, or feel free to comment below with any additional information.

    If you have any other questions, please let me know. Thank you again for your time and patience throughout this issue.

     

    Please don’t forget to Accept Answer and Yes for "was this answer helpful" wherever the information provided helps you, this can be beneficial to other community members.

    Thank You.

    1 person found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2025-05-20T14:59:57.79+00:00

    To determine if a number is an even number divide by 0 and check remainder.

    Dim isEven = (value mod 2 = 0)
    Dim isOdd = (value mod 2 <> 0)
    
    0 comments No comments

  2. Viorel 122.5K Reputation points
    2025-05-20T15:02:37.76+00:00

    Try these expressions too: WorksheetFunction.IsOdd(some_value), WorksheetFunction.IsEven(some_value).


  3. Dick Mezzanotte 20 Reputation points
    2025-05-21T15:47:59.5233333+00:00

    Thank you for the direction, here is how I solved my issue:

    Sub MacroTest()

    Dim R_owe As Variant

    Dim cur_row As Integer

    Dim Val As Double

    Dim ans As String

    R_owe = 2

    While R_owe < 15

    If (WorksheetFunction.IsEven(Range(Cells(R_owe, 7), Cells(R_owe, 7)).Value)) _
    
      Then
    
        ans = "EVEN"
    
      Else
    
        ans = "Odd"
    
    End If
    
    Range(Cells(R_owe, 9), Cells(R_owe, 9)) = ans
    
    R_owe = R_owe + 1
    

    Wend

    End Sub


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.