UDF for converting letter ratings to number and multiplying by percentages for performance ratings

lmoseley7

Board Regular
Joined
Jul 9, 2013
Messages
151
I would like to write a User Defined Function to calculate performance ratings. Our employees are rated on a scale of I, M-, M, M+, E, where I would be the lowest level and E would be the highest. You can assign a number to each of these ratings from 1 to 5. Employees are then graded on each of their job responsibilities, which are weighted as a percentage of their total performance rating. For instance, say an employee has 5 areas of responsibility that are rated 10%, 25%, 35%, 25% and 5%, you would then multiply these percentages by the rating (1-5) to get an overall rating.

I've never written a UDF, but I've used several I've found on the internet and have updated some to fix issues, so I have some experience with them. As it stands, the ratings and weightings are not in contiguous ranges, although that could be overcome. If it were possible to write the UDF to accept two non-contiguous ranges that would be great, but not necessary. The data currently exists with the rating in once cell and the weighting in the cell directly below it, then the next rating might be 20+ rows down the page. Following is my poor attempt at trying to come up with the basis for the UDF.

The function as used in Excel would work like this:

=ePerformance(range of ratings which would be converted to numbers, range of weightings to be multiplied by the converted ratings)

In VBA it would look like:

Function ePerformance (Ratings As Range, Weightings As Range)

Dim rCell as Range
Dim eRating as Integer
Dim weightedRating as Integer
'Not sure what other variables I might need to declare here or if I've done these correctly

weightedRating = 0

For each rCell in Ratings
If rCell.Value = "E" Then
eRating = 5
If rCell.Value = "M+" Then
eRating = 4
If rCell.Value = "M" Then
eRating = 3 '

I don't expect my staff to get a rating below M, but if they would I think I could figure out the rest of the code
End If

'At this point I would need to multiply the resulting eRating by the corresponding weighting.
'I'm not sure how to cycle through the second range of weightings to make sure that I'm using the correct one.
'Also, I would need to keep up with the product of the weighting*rating to keep a running total

weightedRating = weightedRating + (eRating * Weight1,2,3, etc)
Next rCell

ePerformance = weightedRating
End Function

Ultimately, if I could reconvert the rating back to the letter grade that would be awesome, but if I can just get some help on the bulk of the function above, that would be enough. Any help I could get would be appreciated. Hopefully what I learn here I can apply to future functions that I might want to build. Is there anyway to write the function to accept a non-contiguous range? In the top of the function, could you write it like this:

Function ePerformance((Range1, Range2, Range3, ...),(Range 1, Range2, Range3, ...))

Thanks
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I tried the function as entered below where the Weightings range was one cell or a range of cells that matched the size of the Ratings range and either way I do it I get a Compile error: Next without For. As you can see there is clearly a For statement. Although I'm sure the function isn't written correctly, I wouldn't expect this error.

Function ePerformance(Ratings As Range, Weightings As Range)
Dim rCell As Range
Dim eRating As Integer
Dim weightedRating As Integer
'Not sure what other variables I might need to declare here or if I've done these correctly
weightedRating = 0
For Each rCell In Ratings
If rCell.Value = "E" Then
eRating = 5
If rCell.Value = "M+" Then
eRating = 4
If rCell.Value = "M" Then
eRating = 3

'I don't expect my staff to get a rating below M, but if they would I think I could figure out the rest of the code
End If
'At this point I would need to multiply the resulting eRating by the corresponding weighting.
'I'm not sure how to cycle through the second range of weightings to make sure that I'm using the correct one.
'Also, I would need to keep up with the product of the weighting*rating to keep a running total
weightedRating = weightedRating + (eRating * Weightings)
Next rCell
ePerformance = weightedRating
End Function
 
Upvote 0
If I close the other If statements with two additional End Ifs then I no longer get the Compile error. Unfortunately I get an error when using the function in the workbook as written.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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