RoundUp and RoundDown in VBA

Lima Mike

Board Regular
Joined
Jun 3, 2003
Messages
70
Dear All,

I tried to use the functions roundup and rounddown in VBA but it does not work.
In a spreadsheet they do but not in VBA.
Can't find help in HELP.

Anybody that can help?

Lima Mike
 
If one must use a very large number of small integers, yes, size matters.

If one is drawing a picture with a large number of pixels, yes, size matters.

For the run-of-the-mill programs that I see, where maybe a few thousand integers, at best, are involved, it hardly seems important at all to use less bytes for numbers. For instance, strings take up, as I understand it, two bytes plus one byte more per character, yet I don't see anybody fussing about making strings as short as possible. Why? Because only a few strings are usually involved, making economy of string size an unrealistic way of "saving" memory space. So, as long as one is using a relatively small number of integers, it seems to me an overkill to try to "save" memory space. I see this in programs with only a few integers, as in a FOR I = 1 to 4...NEXT I loop, in which the programmer has already done a DIM I AS INTEGER.

Yes, I know, "we must get used to saving space always, so that, when we really need it, our program will not fall short." Hooey! I say, always use the easiest and must readable code you can use, including using the default values which, in BASIC, are the 6-digit single-precision floating-point numbers. Then, when and if you REALLY need simple or double integers, DIMension them at that time and occasion.

I will now stand straight and tall in front of the Programmer's Guild firing squad, condemned for heresy on the subject of not following the sacred commendment, "Thou shalt always DIMension AS INTEGER any and all numbers that are to be used as integers, unless they HAVE to be DIMmed AS DOUBLE".
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
RalphA said:
just_jon:
Hmm, "...a Long can be from -2,145,483,648 to 2,147,483,647". But, since in Excel spreadsheets I can write the number 214,784,836,481,234, which has 15 digits, versus the above long integers, with only 10 digits, why use long integers at all, since Excel provides 15 integers already?

Hi again, have a look at the help topic Data Type Summary. The 15 digits you see in a cell is actually stored as a Double data type. As an example, type a 15 digit number in a cell then run this code...

Code:
Sub DataTypes()
MsgBox "The active cell is data type " & _
    UCase(TypeName(ActiveCell.Value))
End Sub

EDIT: As to your other comments about declaring variables etc then yes your right, saving space with 2 bytes versus 8,16 etc is hardly significant and is not really an issue in todays environment unless theres a huge amount of data to be stored in memory.

However, I declare variables for 2 reasons:
1) I do this out of habit to ensure that the data type used is what I want when doing calculations, which may not always be the case when Excel converts a data type from variant to whatever.
2) Other people reading the code can see the intended data type for a particular variable which adds clarity for long pieces of code.
 
Upvote 0
Sub Time_Converter(ByVal Value As Double, ByRef hours As Double, ByRef minutes As Double, ByRef seconds As Double)
hours = CInt(Int(Value))
minutes = Int(60 * (Value - hours))
seconds = Int(3600 * (Value - hours - (minutes / 60)))
End Sub



Dear All,

I tried to use the functions roundup and rounddown in VBA but it does not work.
In a spreadsheet they do but not in VBA.
Can't find help in HELP.

Anybody that can help?

Lima Mike
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,517
Members
448,968
Latest member
Ajax40

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top