Hello -
Attached is a workbook that allows user to compute new pricing based on established criteria. Everything works great except when I apply a discount of say 10%, the result is not rounded properly. Anyway to fix this rounding issue using VBA code? FYI... I know I can easily correct this situation by inputing a formula directly in the worksheet itself but I'm trying to learn how to effect these sorts of changes using VBA.
Thanks!
Grilleman
Sub PriceIncrease()
'Calculator that allows user to adjust pricing by Business Group, by Product Group, by Material
Dim Rows As Long
Dim Rg As Range
Set Rg = Range("A1").CurrentRegion
Dim BizGrp As String
BizGrp = Range("K3")
Dim ProGrp As String
ProGrp = Range("K4")
Dim Material As String
Material = Range("K5")
Dim Adjustment As Double
Adjustment = Range("K6")
Dim i As Long
For i = 2 To Rg.Rows.Count
If Cells(i, 1) = BizGrp And Cells(i, 2) = ProGrp And Cells(i, 4) = Material Then
Cells(i, 6) = Cells(i, 5) * Adjustment
End If
If Cells(i, 6) <> 0 Then
Cells(i, 7) = Cells(i, 5) + Cells(i, 6)
Cells(i, 8) = (Cells(i, 7).Value2 - Cells(i, 5).Value2) / Cells(i, 5).Value2
Rg.Cells(i, 8).NumberFormat = "0.00%" ' HERE'S THE LINE OF CODE THAT RETURNS PERCENT TO A TWO DIGIT PRECISION.
ElseIf Cells(i, 6) = "" Then
Cells(i, 7) = Cells(i, 5).Value2
End If
Next i
Dim Myrow As Range
Set Rg = Range("A1").CurrentRegion
Set Rg = Rg.Offset(1, 0)
Set Rg = Rg.Resize(Rg.Rows.Count - 1)
For Each Myrow In Rg.Rows
If Myrow.Row Mod 2 = 0 Then
Myrow.Interior.Color = RGB(204, 204, 255)
End If
Next Myrow
End Sub
Bookmarks