or you can use Below VBA Code:
Follow Below Steps:
1: Activate your file
2: Press Alt+F11
3: In Exteam Left side You can see list of your sheets. Just Right Click any of the sheet
4: Click Insert--->Module
5: Paste Below code in Blank Area
6: Press F5
Code:
Sub CalculatePrice()
Dim rngCell As Range
Dim rngCellC As Range
Dim rngCellR As Range
Dim rngWholeC As Range
Dim rngWholeR As Range
Dim rngWholeRow As Range
Dim rngWhole As Range
Dim rngQuality As Range
Dim lngCol As Long
Dim lngRow As Long
Dim sngPrice As Single
With ThisWorkbook.Worksheets("HJD-sono")
Set rngWholeC = .Range(.Range("C3"), .Cells(3, .Columns.Count).End(xlToLeft))
Set rngWholeR = .Range("A4:A" & .Range("A" & .Rows.Count).End(xlUp).Row)
End With
With ThisWorkbook.Worksheets("XXX")
Set rngWhole = .Range("A2:A" & .Range("A" & .Rows.Count).End(xlUp).Row)
For Each rngCell In rngWhole
'Finding Column
For Each rngCellC In rngWholeC
On Error GoTo X1:
If rngCell.Value >= CLng(Mid(rngCellC.Value, 1, InStr(1, rngCellC.Value, "-"))) And rngCell.Value <= CLng(Mid(rngCellC.Value, InStr(1, rngCellC.Value, "-") + 1, Len(rngCellC.Value) - InStr(1, rngCellC.Value, "-"))) Then
X1:
lngCol = rngCellC.Column
Exit For
End If
Next rngCellC
'Finding Quality
Set rngWholeRow = Nothing
For Each rngQuality In rngWholeR
If rngQuality.Value = rngCell.Offset(, 2).Value Then
If rngWholeRow Is Nothing Then
Set rngWholeRow = rngQuality
Else
Set rngWholeRow = Union(rngWholeRow, rngQuality)
End If
End If
Next
'Finding Row
Set rngWholeRow = rngWholeRow.Offset(, 1)
For Each rngCellR In rngWholeRow
On Error GoTo X2:
If rngCell.Offset(, 1).Value >= CLng(Mid(rngCellR.Value, 1, InStr(1, rngCellR.Value, "-") - 2)) And rngCell.Offset(, 1).Value <= CLng(Trim(Mid(rngCellR.Value, InStr(1, rngCellR.Value, "-") + 1, Len(rngCellR.Value)))) Then
X2:
lngRow = rngCellR.Row
Exit For
End If
Next rngCellR
'Finding Price
With ThisWorkbook.Worksheets("HJD-sono")
sngPrice = .Cells(lngRow, lngCol).Value
End With
'Calculating Exact Price
If rngCell.Offset(, 3).Value = "a" Then
rngCell.Offset(, 4) = sngPrice + (sngPrice * 0.1)
ElseIf rngCell.Offset(, 3).Value = "b" Then
rngCell.Offset(, 4) = sngPrice + (sngPrice * 0.075)
ElseIf rngCell.Offset(, 3).Value = "c" Then
rngCell.Offset(, 4) = sngPrice + (sngPrice * 0.05)
ElseIf rngCell.Offset(, 3).Value = "d" Then
rngCell.Offset(, 4) = sngPrice + (sngPrice * 0.025)
ElseIf rngCell.Offset(, 3).Value = "e" Then
rngCell.Offset(, 4) = sngPrice
End If
Next rngCell
End With
End Sub
Bookmarks