Even and Odd in VBA

Tessel75 -  
 Tessel75 -
Hello everyone,
How do you write that a number is even or odd in VBA, please?
Thank you

Configuration: Windows / Firefox 93.0

3 answers

  1. PapyLuc51 Posted messages 4569 Registration date   Status Member Last intervention   1 511
     
    Hello,

    The practical sheet linked in the second link under the question (in the "See also" section) answers the request.

    Another possibility is to use one of the two functions available, "IS.EVEN()" or "IS.ODD()"

    The number in A1

    =IF(IS.EVEN(A1),"EVEN","ODD")

    or conversely if using the other

    =IF(IS.ODD(A1),"ODD","EVEN")

    Best regards
    0
    1. Anonymous user
       
      Hello everyone,
      PapuLuc51, the request is about VBA.
      There's an article proposing several VBA methods here: https://www.commentcamarche.net/faq/48446-vba-test-si-un-nombre-est-pair-ou-impair

      PS: we can add to the list the functions:
      - WorksheetFunction.IsOdd(value_to_test) which returns TRUE/FALSE depending on whether the value to test is ODD/even
      - WorksheetFunction.IsEven(value_to_test) which returns TRUE/FALSE depending on whether the value to test is EVEN/odd
      0
      1. PapyLuc51 Posted messages 4569 Registration date   Status Member Last intervention   1 511 > Anonymous user
         
        Hello RoMa_31
        Yes, that’s what I mention in the first sentence of my response; the rest is to remind of the other possibility with functions

        Best regards
        0
      2. Anonymous user > PapyLuc51 Posted messages 4569 Registration date   Status Member Last intervention  
         
        Indeed!
        I skimmed through your response ;-)
        0
    2. Tessel75
       
      Thank you for the response, I will look at the link because actually I will need to use it with Access if necessary by creating a new personal function.
      0
  2. Tessel75
     
    Very nice answer from LePingou, (we're used to it), it's exactly what I was looking for even though my problem was about continuous recording rather than odd and even pages.

    I'm finishing writing my code; and then I will mark it as "resolved".

    Thank you all for your efforts to help me reach a solution.
    0