Reputation: 10113
I want to create a macro to edit the price list my faulty ERP packet generates. I currently get 175,42$, etc and I would like to round them to 175,4$ (depending on the second decimal).
J K
175,42 175,4
193,76 193,8
dim i as integer
For i = 16 to 25
Range("K" & i).Select = "=ROUND(J & i;1)"
Next i
So I presume this should run through K16:K25 and use the round function, but it seems to give an error and I'm guessing it's the round function.
Upvotes: 0
Views: 6847
Reputation: 149287
Try this (UNTESTED)
Sub Sample()
Dim i As Integer
For i = 16 To 25
Sheets("Sheet1").Range("K" & i).Formula = "=ROUND(J" & i & ",1)"
Next i
End Sub
Upvotes: 1
Reputation: 2910
Try this instead. VBA has its own function for Round.
Now tested and working for me!
dim i as integer
For i = 16 to 25
Range("K" & i) = Round(Range("J" & i), 1)
Next i
Upvotes: 2
Reputation: 53137
Change your code to
Range("K" & i).Formula = "=ROUND(J" & i & ";1)"
Upvotes: 3