English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

There is an ISNUMBER function, but is there a way to only do something if the number is an integer?

I was think of something like this:
=IF(ISNUMBER((1/8)*$D5+(1/8)*F$3),(1/8)*$D5+(1/8)*F$3,"")
but instead of IFNUMBER, some kind of IFINTEGER

There is an INT that just rounds it to an integer, but that's not what I want.

2007-12-31 14:58:01 · 2 answers · asked by Jack 3 in Computers & Internet Software

2 answers

You can use ISNUMBER in combination with AND, IF, INT or MOD. MOD returns the remainder. Below are the two easiest ways I know to find if the number is an integer.

=AND(ISNUMBER(F21), INT(F21)=F21)

Or

=AND(ISNUMBER(F21), MOD(F21, 1) = 0)

Excel doesn't have an IFINTEGER function that I know of. But if you know VBA programming. You can write a function called IFINTEGER, then you can use a much more simplified formula to come up with your answer. The only problem is when you transfer the file to someone else's computer. They'll need the value and not the formula because if they don't have that function added to theirs, then their computer won't be able to use that formula. Below is the programming code you'd need to enter. Just record a macro by going to Tools > Macro > Record Macro. Then go back and Edit the macro by going to: Tools > Macro > Macros... Then select the macro and click the Edit button. Delete all of the text out and paste the code in below.

Function IFINTEGER(MyString) As Boolean

IFINTEGER = False
If Application.WorksheetFunction. _
IsNumber(MyString) = True Then
If Fix(MyString) = MyString Then
IFINTEGER = True
End If
End If

End Function

You can then enter and use the new function you created:

=IFINTEGER(F21)

PS - The first answer has one major flaw. It doesn't account for the fact of determining whether the cell is actually a number or not.

2008-01-02 00:55:29 · answer #1 · answered by devilishblueyes 7 · 1 0

Well, you could do a comparison IF statement on the value using rounding.

IF(INT($D5) = $D5, "Yes", "No")

This converts $D5 to an Integer value by rounding down, then compares it to the original value. If it were an Integer, the value would have stayed the same.

To appease the user below, here's a full statement including string values, regardless of the fact the topic creator distinctly said "if the number is an integer".

=IF(ISNUMBER($D5),IF(INT($D5) = $D5, "Yes", "No"), "No")

2007-12-31 23:15:54 · answer #2 · answered by Zurahn 4 · 4 0

fedest.com, questions and answers