Use a cell value to several decimal pfrom a worksheet named range in a formula in a macro

chappy

New Member
Joined
Jul 18, 2006
Messages
42
Office Version
  1. 365
Platform
  1. Windows
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.

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
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Not sure if I follow exactly what you were asking for, as far as I can see you just need to change the commPS definition to
VBA Code:
commPS = Range("COMM_PER_SHARE")
You would only need to qualify it with a reference to the sheet if the named range is scoped to worksheet level instead of workbook level.
 
Upvote 0
Not sure if I follow exactly what you were asking for, as far as I can see you just need to change the commPS definition to
VBA Code:
commPS = Range("COMM_PER_SHARE")
You would only need to qualify it with a reference to the sheet if the named range is scoped to worksheet level instead of workbook level.
Thanks for posting a reply Jason. Much appreciated!
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,812
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top