IF <> to integer?

antman123

Board Regular
Joined
Jan 24, 2005
Messages
72
In Excel how would I code a statement that made sure that a variable was an integer. e.g.

IF DeskNumber /= integer THEN

Thanks
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
How about

IF INT(DeskNumber) = DeskNumber THEN
..stuff if desknumber is an integer
ELSE
..stuff if desknumber is not an integer
END IF
 
Upvote 0
Or, same as Cherria's but with a formula instead of VBA,

=IF(A1=INT(A1),"A1 houses an integer", "A1 does not house an integer")
 
Upvote 0
Yes, but its more of a validation thing im trying to get. So if the user types in letters instead of numbers, then the ELSE part is executed (an error msg)
 
Upvote 0
Something like this perhaps:-

=IF(NOT(ISNUMBER(A1)),"This is text or blank",IF(A1=INT(A1),"Valid Integer","Number with Decimals"))
 
Upvote 0
Thanks... That last one that uses ISNUMBER is exactly what i want. Only problem is that I cant use the ISNUMBER bit in VBA. Any ideas?

Thanks
 
Upvote 0
"Yes, but its more of a validation thing im trying to get. So if the user types in letters instead of numbers, then the ELSE part is executed (an error msg)"

You could use Data Validation and either Allow Whole number of Decimal or use a custom formula =ISNUMBER(A1).
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,267
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top