# Fixed Modules

#### Gerrit.B

##### Board Regular
Why discussing if some answer are alreay fixed on this forum/internet.
Would it help if everybody could post every finished module with explaination what the module does.
In that way you get all fixed module in 1 post

This was found somewhere on the internet and it works.

********************************************************

Option Compare Database
Option Explicit
Public Function fctRoundUpDown( _
varNumber As Variant, varDelta As Variant) As Variant
'***********
'Name: RoundDelta (Function)
'Purpose: round varNumber to varDelta, up or down
'Inputs: varNumber = number to round
' varDelta = rounding precision
' +varDelta = rounds UP
' -varDelta = rounds DOWN
'Example: RoundUpDown(5.12,+0.25) = 5.25
' RoundUpDown(5.12,-0.25) = 5.00
'Output: varNumber rounded UP/DOWN
'***********

Dim varTemp As Variant
varTemp = CDec(varNumber / varDelta)
If Int(varTemp) = varTemp Then
fctRoundUpDown = varNumber
Else
fctRoundUpDown = Int( _
((varNumber + (2 * varDelta)) / varDelta) - 1) _
* varDelta
End If
End Function

Public Function RoundNear( _
varNumber As Variant, varDelta As Variant) As Variant
'***********
'Name: RoundNear (Function)
'Purpose: rounds varnumber to the nearest fraction equal
' varDelta
'Inputs: varNumber - number to round
' varDelta - the fraction used as measure of
' rounding
'Example: RoundNear(53,6) = 54
' RoundNear(1.16,0.25) = 1.25
' RoundNear(1.12,0.25) = 1.00
' RoundNear(1.125,0.25)= 1.25
'Output: varNumber rounded to nearest
' multiple of varDelta.
'***********

Dim varDec As Variant
Dim intX As Integer
Dim varX As Variant

varX = varNumber / varDelta
intX = Int(varX)
varDec = CDec(varX) - intX

If varDec >= 0.5 Then
RoundNear = varDelta * (intX + 1)
Else
RoundNear = varDelta * intX
End If
End Function

********************************************************

### Excel Facts

Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
I really don't think that is a a feasible idea. There are infinite number of modules that could be written for an infinite number of problems. Then it becomes a matter of trying to "find a needle in a haystack".

This board/forum is designed to be a question and answer type forum. We encourage the use of the Search functionality to search old threads for solutions to problems that may have been asked before. However, for that to work best, it is important to use descriptive titles. Like in this instance, a title like "Rounding Via VBA" would be better than "Fixed Modules".

1,219,808
Messages
6,150,353
Members
450,954
Latest member
Vd1408

### 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.

### Which adblocker are you using?

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

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