Multiplying select case variables

Deuce Bucksman

Board Regular
Joined
Jan 17, 2011
Messages
102
Quick Question: does anyone know how to use a formula within a select case structure? Essentially, i'm trying to make the below case strucutre to calculate commisions based on the sales input. Everytime I try to multiply the variable comish into the Case value (14%), it keeps giving me an error. Any advice? Thanks!

Function Commision()
Dim Comish
Comish = 25000

Case1 = 0.08
Case2 = 0.1
Case3 = 0.12
Case4 = 0.14

Select Case Comish
Case 0 To 5000: commish (Case1)
Case 5001 To 10000: commish (Case2)
Case 10001 To 15000: commish (Case3)
Case Else: commish (Case4)
End Select
End Function
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
What is that supposed to do?

Maybe this:

Code:
Function Commission(Amount As Double) As Double
    If Amount >= 0 Then
        Commission = WorksheetFunction.Lookup(Amount, _
                                              Array(0, 5001, 10001, 15001), _
                                              Array(0.08, 0.1, 0.12, 0.14))
    End If
End Function
 
Upvote 0
The objective is to create a function that will automatically multiply the correct percentage against the number dropped into the formula. I just couldnt figure out how to multiply in a select case structure, but i'm going to give your alternative a go. Thanks!
 
Upvote 0
Then
Code:
Function Commission(Amount As Double) As Double
    If Amount >= 0 Then
        Commission = Amount * WorksheetFunction.Lookup(Amount, _
                                              Array(0, 5001, 10001, 15001), _
                                              Array(0.08, 0.1, 0.12, 0.14))
    End If
End Function

=Comission(10000) returns 1000
 
Upvote 0
The multiplication operator in VBA is *. OTOH, VBA doesn't understand Comish (Case1) in the context in which it is written.
Quick Question: does anyone know how to use a formula within a select case structure? Essentially, i'm trying to make the below case strucutre to calculate commisions based on the sales input. Everytime I try to multiply the variable comish into the Case value (14%), it keeps giving me an error. Any advice? Thanks!

Function Commision()
Dim Comish
Comish = 25000

Case1 = 0.08
Case2 = 0.1
Case3 = 0.12
Case4 = 0.14

Select Case Comish
Case 0 To 5000: commish (Case1)
Case 5001 To 10000: commish (Case2)
Case 10001 To 15000: commish (Case3)
Case Else: commish (Case4)
End Select
End Function
 
Upvote 0
Thanks! everytime I used the * multiplier it gave me an error. What I did was added another variable "bonus" and used an = sign to connect comish and the different cases. So now it works. Thanks for the collaborative effort. I appreciate everyones help!
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,331
Members
452,907
Latest member
Roland Deschain

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