ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Get next Integer value (https://www.excelbanter.com/excel-programming/291390-get-next-integer-value.html)

Stuart[_5_]

Get next Integer value
 
If I Dim i As Integer
and then test "A1" for its' value
and if the value in "A1" is 3.00000000000000 and 1

How can I return i = 4 , please?

ie any value 3 but < 4 returns 4

Regards.




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.586 / Virus Database: 371 - Release Date: 12/02/2004



Chip Pearson

Get next Integer value
 
Stuart,

I'm not sure what your question is. A variable declared as
Integer can only hold whole numbers, no fractional part, so the
variable will be either 3 or 4, but never a number between the
two. If you need to include a fractional part, declare the
variable as Double.



"Stuart" wrote in message
...
If I Dim i As Integer
and then test "A1" for its' value
and if the value in "A1" is 3.00000000000000 and 1

How can I return i = 4 , please?

ie any value 3 but < 4 returns 4

Regards.




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.586 / Virus Database: 371 - Release Date:

12/02/2004





Rob van Gelder[_4_]

Get next Integer value
 
i = -int(-3.000000000000001)

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Stuart" wrote in message
...
If I Dim i As Integer
and then test "A1" for its' value
and if the value in "A1" is 3.00000000000000 and 1

How can I return i = 4 , please?

ie any value 3 but < 4 returns 4

Regards.




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.586 / Virus Database: 371 - Release Date: 12/02/2004





Vasant Nanavati

Get next Integer value
 
Or:

Dim i As Integer
i = WorksheetFunction.Ceiling(Range("A1"), 1)

--

Vasant

"Rob van Gelder" wrote in message
...
i = -int(-3.000000000000001)

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Stuart" wrote in message
...
If I Dim i As Integer
and then test "A1" for its' value
and if the value in "A1" is 3.00000000000000 and 1

How can I return i = 4 , please?

ie any value 3 but < 4 returns 4

Regards.




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.586 / Virus Database: 371 - Release Date: 12/02/2004







Bob Phillips[_6_]

Get next Integer value
 
If he declares it as integer, it will implicitly do what is advised here, it
cannot be 3.000000000000001

Bob

"Rob van Gelder" wrote in message
...
i = -int(-3.000000000000001)

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Stuart" wrote in message
...
If I Dim i As Integer
and then test "A1" for its' value
and if the value in "A1" is 3.00000000000000 and 1

How can I return i = 4 , please?

ie any value 3 but < 4 returns 4

Regards.




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.586 / Virus Database: 371 - Release Date: 12/02/2004







Stuart[_5_]

Get next Integer value
 
Many thanks all.

Used Vasant's solution and appears fine.
Did not post clearly.
Here was the situation:

Col A contains text values or integers and empty cells.
Each numeric value represents the end of a 'page' and
they are sequential.

If the last numeric value in the range is less than 25 then
they will all transfer to 1 Collection page. If more than
24 then I need to find the number of Collection pages.

I'm using:

CollectionPages = LastPageNo / 24 'returns a decimal value
and
CollectionPages = WorksheetFunction.Ceiling(CollectionPages, 1)
which increments CollectionPages to the next integer, if need be.

Regards.


"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Or:

Dim i As Integer
i = WorksheetFunction.Ceiling(Range("A1"), 1)

--

Vasant

"Rob van Gelder" wrote in message
...
i = -int(-3.000000000000001)

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Stuart" wrote in message
...
If I Dim i As Integer
and then test "A1" for its' value
and if the value in "A1" is 3.00000000000000 and 1

How can I return i = 4 , please?

ie any value 3 but < 4 returns 4

Regards.




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.586 / Virus Database: 371 - Release Date: 12/02/2004








---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.586 / Virus Database: 371 - Release Date: 12/02/2004



Rob van Gelder[_4_]

Get next Integer value
 
Not sure what you mean?

This example rounds up.

Sub test()
Dim dbl As Double, i As Long

dbl = 3.1
i = -Int(-dbl)
MsgBox i
End Sub

(using 3.1, 3.000000000000001 is precise for VBA)


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Bob Phillips" wrote in message
...
If he declares it as integer, it will implicitly do what is advised here,

it
cannot be 3.000000000000001

Bob

"Rob van Gelder" wrote in message
...
i = -int(-3.000000000000001)

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Stuart" wrote in message
...
If I Dim i As Integer
and then test "A1" for its' value
and if the value in "A1" is 3.00000000000000 and 1

How can I return i = 4 , please?

ie any value 3 but < 4 returns 4

Regards.




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.586 / Virus Database: 371 - Release Date: 12/02/2004









Tom Ogilvy

Get next Integer value
 
I suspect Bob is talking about the argument to int being an integer,
therefore it can't be

3.0000000000000001 or what ever

There was some concern that Stuart was saying an integer had a decimal
portion. Stuarts later posting shows his number is produce by a division
and therefore is not a decimal, but he wants to round up to the next higher
integer. 3.00000000001 pages requires a total of 4 pages.

--
Regards,
Tom Ogilvy

"Rob van Gelder" wrote in message
...
Not sure what you mean?

This example rounds up.

Sub test()
Dim dbl As Double, i As Long

dbl = 3.1
i = -Int(-dbl)
MsgBox i
End Sub

(using 3.1, 3.000000000000001 is precise for VBA)


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Bob Phillips" wrote in message
...
If he declares it as integer, it will implicitly do what is advised

here,
it
cannot be 3.000000000000001

Bob

"Rob van Gelder" wrote in

message
...
i = -int(-3.000000000000001)

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Stuart" wrote in message
...
If I Dim i As Integer
and then test "A1" for its' value
and if the value in "A1" is 3.00000000000000 and 1

How can I return i = 4 , please?

ie any value 3 but < 4 returns 4

Regards.




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.586 / Virus Database: 371 - Release Date: 12/02/2004












All times are GMT +1. The time now is 08:33 AM.

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