Fixed Modules

Gerrit.B

Board Regular
Joined
Aug 10, 2004
Messages
234
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
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

I will start with first module for rounding numbers
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

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.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
58,379
Office Version
  1. 365
Platform
  1. Windows
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".
 

Forum statistics

Threads
1,137,063
Messages
5,679,401
Members
419,825
Latest member
MegastarMagus

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
Top