Get next Integer value

  • Thread starter Thread starter Stuart
  • Start date Start date
S

Stuart

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.
 
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.
 
If he declares it as integer, it will implicitly do what is advised here, it
cannot be 3.000000000000001

Bob
 
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.
 
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)
 
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.
 
Back
Top