Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Is variable an integer?

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Is variable an integer?

Otto,

An alternative

If Range("D6") = Int(Range("D6")) Then
MsgBox "Integer"
Else
MsgBox "Not an integer"
End If

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Otto Moehrbach" wrote in message
...
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Is variable an integer?

Hi Otto

just to add to Bob's and Jake' suggestion why your line
MsgBox Application.WorksheetFunction.Mod(Range("D6"),1)
did produce an error.
WorksheetFunction.Mod is not supported as VBA directly implements the
MOD function. So the corret syntax would be:
MsgBox Range("D6").value mod 1

Though the other solutions are definetly better

Frank



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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Is variable an integer?

Frank
Correct me if I'm wrong but doesn't the VBA Mod function round all
numbers before it does the division? As I understand it, the VBA mod, as in
"somenumber Mod 1" will always return zero regardless of what "somenumber"
is. Thanks for your help. Otto
"Frank Kabel" wrote in message
...
Hi Otto

just to add to Bob's and Jake' suggestion why your line
MsgBox Application.WorksheetFunction.Mod(Range("D6"),1)
did produce an error.
WorksheetFunction.Mod is not supported as VBA directly implements the
MOD function. So the corret syntax would be:
MsgBox Range("D6").value mod 1

Though the other solutions are definetly better

Frank



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







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Is variable an integer?

Thanks Bob & Jake. My plan is to first test (with IsNumerical) that it is a
valid number, then test for integer. It is supposed to be an integer every
time. Thanks again for your help. Otto
"Otto Moehrbach" wrote in message
...
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




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Is variable an integer?

Otto Moehrbach wrote:
Frank
Correct me if I'm wrong but doesn't the VBA Mod function round

all
numbers before it does the division? As I understand it, the VBA
mod, as in "somenumber Mod 1" will always return zero regardless of
what "somenumber" is. Thanks for your help. Otto
"Frank Kabel" wrote in message
...


Hi Otto
you're right. It uses only the integer values for the division
(according to the Excel helpfile)

Frank

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Is variable an integer?

Thanks for the help. I'm always learning. Otto
"Frank Kabel" wrote in message
...
Otto Moehrbach wrote:
Frank
Correct me if I'm wrong but doesn't the VBA Mod function round

all
numbers before it does the division? As I understand it, the VBA
mod, as in "somenumber Mod 1" will always return zero regardless of
what "somenumber" is. Thanks for your help. Otto
"Frank Kabel" wrote in message
...


Hi Otto
you're right. It uses only the integer values for the division
(according to the Excel helpfile)

Frank



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I add an integer to an existing integer? Aaron Excel Worksheet Functions 3 December 17th 09 09:46 PM
integer integer format Excel Worksheet Functions 1 May 3rd 07 06:45 PM
OutlineLevel and Integer Variable issue jurgenC![_2_] Excel Programming 2 January 30th 04 10:32 PM
Not seeing integer Martin Wheeler Excel Programming 1 September 4th 03 03:29 AM
Use of integer variable for sizing of matrix Cor Steeghs Excel Programming 2 August 8th 03 12:56 PM


All times are GMT +1. The time now is 03:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"