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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

cherria

Well-known Member
Joined
Nov 17, 2004
Messages
708
How about

IF INT(DeskNumber) = DeskNumber THEN
..stuff if desknumber is an integer
ELSE
..stuff if desknumber is not an integer
END IF
 

Oaktree

MrExcel MVP
Joined
Jun 20, 2002
Messages
8,021
Office Version
  1. 365
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")
 

antman123

Board Regular
Joined
Jan 24, 2005
Messages
72
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)
 

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995

ADVERTISEMENT

Hi,

I think you can use TypeName(variable)

hope this helps

jindon
 

KenWright

Active Member
Joined
Jan 14, 2005
Messages
267
Something like this perhaps:-

=IF(NOT(ISNUMBER(A1)),"This is text or blank",IF(A1=INT(A1),"Valid Integer","Number with Decimals"))
 

antman123

Board Regular
Joined
Jan 24, 2005
Messages
72

ADVERTISEMENT

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
 

inarbeth

Well-known Member
Joined
Apr 8, 2002
Messages
912
"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).
 

Forum statistics

Threads
1,148,529
Messages
5,747,230
Members
424,070
Latest member
smanni3

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
Top