ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   test if a value is an integer (https://www.excelbanter.com/excel-programming/341705-test-if-value-integer.html)

pablo bellissimo

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

Norman Jones

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




Stefi

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


Norman Jones

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




Norman Jones

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




Stefi

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






All times are GMT +1. The time now is 05:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com