Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a way of identifying whether a result is an integer

Status
Not open for further replies.

MacroScope

Programmer
Jul 17, 2010
286
US
I need to identify whether a number is or is not a whole number. The Int function will convert a number like 18.6 to 18, but I don't want that. I want something equivalent to an IsInt function (which I know doesn't exist) which would return True for 18 and false for 18.6.

Any suggestions on how I can accomplish that?
 
Another way of stating my request is that I'd like to know if number 1 is evenly divisible by number 2. 10 and 2 would result in a True, while 9 and 2 would result in a false.
 

How about...

Code:
If Int(x) < x Then
   Debug.Print x & " is not an integer"
End If

Randy
 
Thanks. I was able to get it by using the Mod function. The problem is coming from an f'd-up date format provided in an Excel spreadsheet. That's another story, but I want to find out if the month of the date provided is at 12 month intervals from a date in our system. I used the DateDiff function to subtract the months between the two values and give me a result. I then applied Mod 12 to that result, and if it results in a 0 it's an exact year (to the month) from the stored date. If it's any other number, then of course it isn't.

Thanks to all for jumping in.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top