Make your own free website on Tripod.com

VBA- Rounding Numbers in MS Excel

 

Yesterday I saw a peculiar question in Yahoo! "Ask a question and answer" section about rounding numbers in MS Excel. He wants all the numbers to round off to 00 for the last two digits and 0 for all the decimal places. For example, 1234.456   becomes 1200.00, 456788.998  becomes 456800.00 and etc. This can be achieved by creating a VBA which uses the round function. Here is the code, you can try it out yourself.

 

Private Sub CommandButton1_Click()
Dim x, y, w As Double
x = Cells(2, 1)
y = x / 100
w = Round(y, 0) * 100

Cells(3, 1) = w

Range("A3").Select
Selection.NumberFormat = "0.00"

End Sub

 

 

 

 

 

 

 [Back to VBToday]