View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Jake Marx[_3_] Jake Marx[_3_] is offline
external usenet poster
 
Posts: 860
Default Is variable an integer?

Hi Otto,

Just to add to Bob's excellent suggestion, you may want to use error
handling in the case that Int or CInt raises an error:

Public Function gbIsInt(rvValue As Variant) As Boolean
On Error Resume Next
gbIsInt = (rvValue = CInt(rvValue))
On Error GoTo 0
End Function

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Otto Moehrbach wrote:
Excel 2003, WinXP
My end goal is to test a cell value, via VBA, to see if it is an
integer. The worksheet Mod function works like this:
Mod(D6,1) returns a 0 if D6 is an integer.
The VBA Mod function rounds all numbers first so I can't use that.
So I used:
MsgBox Application.WorksheetFunction.Mod(Range("D6"),1)
I was hoping to get a 0 if D6 is an integer.
I got an error message that said "Object doesn't support this method".
Where did I go wrong? Thanks for your help. Otto