I would like to define "commPS" as cell E47 on worksheet "INSTRUCTIONS" (excel named range "COMM_PER_SHARE") in the code below (appliedCommision = quantity * commPS ). Ideally I would like to reference the excel named range "COMM_PER_SHARE" rather than cell reference E47. The value is to several decimal places so it should not be treated as a whole number or rounded up.
I anyone could help me define this so I can test it in the code it would be very much appreciated. Thanks in advance.
I anyone could help me define this so I can test it in the code it would be very much appreciated. Thanks in advance.
VBA Code:
Private Sub calculateCommissionPayable(actvSheet As Worksheet)
Dim rw As Range
Dim col As Range
Dim commPS As Double
Dim actvSheet As Worksheet
Dim instructSheet As Worksheet
Dim quantity As Integer 'Current Quantity
Set actvSheet = ActiveWorkbook.Sheets("DAS_DATA")
Set instructSheet = ActiveWorkbook.Sheets("INSTRUCTIONS")
commPS = instructSheet.Range("E47")
For Each rw In actvSheet.UsedRange.Rows 'Looping on each row of Sheet1'
If rw.row <> 1 Then 'Skip first header row'
Dim appliedCommision As Double 'Calculated commission'
quantity = convertToInt(Cells(rw.row, 5).Value)
appliedCommision = quantity * commPS
actvSheet.Cells(rw.row, 14).Value = appliedCommision 'applies commission per ticket
End If 'Check if not First Row'
Next rw
Exit Sub
End Sub