Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default test if a value is an integer

Hiya there,

Can anyone tell me how I can test a variable to see if it is a whole number?

I want to write something like:

do until variable = integer

I am just playing around trying to write something that will generate a list
of prime numbers...

I know how I could test a given list to show True if it is a prime but I
want to create a list of just prime numbers.

Can anyone help?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default test if a value is an integer

Hi Pablo,

Can anyone tell me how I can test a variable to see if it is a whole
number?


Try something like:

'===============
Public Sub Test()
Dim rng As Range
Dim rCell As Range

Set rng = Range("A1:A10")

For Each rCell In rng.Cells
With rCell
If IsNumeric(.Value) Then
If .Value = 1 Then
If .Value = Int(.Value) Then
MsgBox .Value & vbTab & "Integer!"
Else
MsgBox .Value & vbTab & "not an integer!"
End If
End If
End If
End With
Next

End Sub
'<<===============

---
Regards,
Norman



"pablo bellissimo" wrote in
message ...
Hiya there,

Can anyone tell me how I can test a variable to see if it is a whole
number?

I want to write something like:

do until variable = integer

I am just playing around trying to write something that will generate a
list
of prime numbers...

I know how I could test a given list to show True if it is a prime but I
want to create a list of just prime numbers.

Can anyone help?

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default test if a value is an integer

IF yourvariable MOD 1 = 0 THEN

Regards,
Stefi


"pablo bellissimo" wrote:

Hiya there,

Can anyone tell me how I can test a variable to see if it is a whole number?

I want to write something like:

do until variable = integer

I am just playing around trying to write something that will generate a list
of prime numbers...

I know how I could test a given list to show True if it is a prime but I
want to create a list of just prime numbers.

Can anyone help?

Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default test if a value is an integer

Hi Steffi,

IF yourvariable MOD 1 = 0 THEN


From the imediate window:

? 1.25 Mod 1
0

? o Mod 1
0

..---
Regards,
Norman



"Stefi" wrote in message
...
IF yourvariable MOD 1 = 0 THEN

Regards,
Stefi


"pablo bellissimo" wrote:

Hiya there,

Can anyone tell me how I can test a variable to see if it is a whole
number?

I want to write something like:

do until variable = integer

I am just playing around trying to write something that will generate a
list
of prime numbers...

I know how I could test a given list to show True if it is a prime but I
want to create a list of just prime numbers.

Can anyone help?

Thanks



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default test if a value is an integer


From the imediate window:



From the immediate window:

---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Steffi,

IF yourvariable MOD 1 = 0 THEN


From the imediate window:

? 1.25 Mod 1
0

? o Mod 1
0

.---
Regards,
Norman





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default test if a value is an integer

Hi Norman,

Sorry, of course you are right. I mistook remainder for fractional part and
didn't test my answer. The right answer

IF yourvariable - INT(yourvariable) = 0 THEN

I appreciate very much your being particular about spelling.

Regards,
Stefi

"Norman Jones" wrote:


From the imediate window:



From the immediate window:

---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Steffi,

IF yourvariable MOD 1 = 0 THEN


From the imediate window:

? 1.25 Mod 1
0

? o Mod 1
0

.---
Regards,
Norman




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
Calculate mean of test scores from rows of test answers RiotLoadTime Excel Discussion (Misc queries) 1 July 26th 06 05:14 PM
how do I test for Integer? Stephen P Thomas Excel Worksheet Functions 4 July 13th 05 10:30 AM
Get next Integer value Stuart[_5_] Excel Programming 7 February 16th 04 04:48 AM
Not seeing integer Martin Wheeler Excel Programming 1 September 4th 03 03:29 AM


All times are GMT +1. The time now is 12:07 PM.

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

About Us

"It's about Microsoft Excel"