PDA

View Full Version : rounding number problem in vba



malarvel
08-11-2016, 10:14 PM
I have a data in sheet1 range "A1:F15". I have calculate the new basic pay value in G1:G15 using below code,

Private Sub CommandButton1_Click()
Dim i As Integer
Dim irow As Integer

irow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To irow
Cells(i, 7) = Round(Cells(i, 5) + Cells(i, 6), 0) * 2.57
Next i




End Sub

when I execute the code, the value would not be rounded.

How to correct my code?

xavier73
08-11-2016, 11:32 PM
You first have to calculate the salary before you round the value.


Cells(i, 7) = Round(((Cells(i, 5) + Cells(i, 6)) * 2.57), 0)