Test if cell contains integer

  • Hi

    I have recently found the very helpful =isFunction UDF
    at http://www.ozgrid.com/VBA/ExcelIsFormula.htm
    Function IsFormula(Check_Cell As Range)
    IsFormula = Check_Cell.HasFormula
    End Function
    which I dont understand but can use nicely to do very useful conditional formatting.

    I have done 3 hours of looking (F1 help, search ozgrid / search google etc) without getting very far, enough to think that it ought to be possible to create other types of cellchecking.

    Is it possible to create other 'cellchecking' functions? what are they? can I find a list somewhere?

    specifically can I create a function which checks if a cell's contents are an integer (rather than a decimal)?


  • Re: Test if cell contains integer

    The only other specific check you mention is if a cell contains a whole integer rather than a decimal number...

    int(activecell.value) = activecell.Value

    But be aware this works on the underlying value, not the formatted display value...


  • Re: Test if cell contains integer


    Please try not to assume knowledge of the answer when entering a thread title. Please use search friendly terms that as accurately as possible describe your question. I have revised your title for you this time. Thank you.

    You do not need VBA for this. Can easily be done with Excel.

    =IF(INT(A1)=A1, TRUE, FALSE)

    Will tell you if A1 contains an integer.

  • Re: Test if cell contains integer

    Thanks Rob & Cytop, for the fast answers

    I will give these a try.

    However as a more general issue ... would it be possible to create other tests such as:-
    Function IsInt(Check_Cell As Range)
    IsFormula = Check_Cell.HasInteger
    End Function

    What I don't know about is, what options can I use with Check_Cell.Has??? to check for other stuff.

    does this make sense?

  • Re: Test if cell contains integer

    Hello cytop,

    Thanks again for such a fast reply.
    Using your previous reply I have now achieved the conditional formatting which I was aiming for:-
    Starting with cell A295 if I add conditional formating rule :-
    Rule: =INT($A295)<>$A295
    Applies to: =$A$295:$B$312

    Then I can copy the format to range A295:b312
    meaning that the formatting for each row is dependent on the contents of column A for that row (ie is it an integer?)

    **Thanks for my solution.**

    As for Check_cell, I have had a look at the link and the information is well beyond my knowledge level (sad smile) However I plan to experiment with the methods & properties later on, so thanks for that referal also.


  • Re: Test if cell contains integer

    Just remember properties and methods in this context are programming concepts.

    A range (which can be a single cell or a collection of cells) has various attributes (or properties) such as font, colour and other 'physical attributes'.

    It also has 'Methods' which are do-able things.. Activate for example, make the range the current selection in Excel. 'BorderAround' draws a border around it. Cut and Copy are other methods.

    Perhaps that might make the distinction a little clearer.


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!