Excel - Multiple Cell Calculation

为君一笑 提交于 2019-12-13 10:24:43

问题


I'm a teacher and trying to create a mark sheet the problem I have is that assignments are marked using different schemes (i.e. % [1 - 100], Level [1 -4], Letter Grade [F - A]). The problem I have is that I only want to report using one marking scheme and need to convert or calculate the other marking schemes based on the scheme there is it is marked.

I've made an excel worksheet which contains a student names and assignments. The sheet then has 3 other columns, one representing each scheme "Letter", "Level", Percentage a column for each scheme. Now, at any given time there is going to be a value in one of the 'scheme' columns - I need excel to automatically or by macro calculate the appropriate value into the other cells.

For example, there are three assignments each marked with a different scheme on the same sheet.

Assignment 1 - %
Assignment 2 - Level 
Assignment 3 - Letter Grade

How can I get excel to check which mark value exists and then populate/calculate the other two the corresponding values.

Mike got 80% (%) on Assignment 1, but I want excel to populate the level column and letter column with the corresponding values at the same time Level 3 on Assignment 2 excel to calculate corresponding percentage and letter and at the same time for a Letter A on Assignment 3 the corresponding % and level should be calculated.

Don't know if this is possible or makes sense, but I tried VLOOKUP and was not successful because I have to do it all manually - I'm aiming for an automated process.

Sorry if it is not clear or confusing...but I've been at this for two days with no luck and not even sure if what I'm doing is possible.


回答1:


of course it should be first assessed the translation of one rating system to the other and then assume those algorithms to shift between rating grades types

one of the possible approaches could be the following:

Option Explicit

Sub main()
    Dim grades As Variant, levels As Variant
    Dim cell As Range
    Dim index As Double

    grades = Array("F", "E", "D", "C", "B", "A")
    levels = Array(1, 2, 3, 4)

    For Each cell In Intersect(Range("A:C"), ActiveSheet.UsedRange).Offset(1).SpecialCells(xlCellTypeConstants)
        Select Case cell.Column
            Case 1 '%
                index = cell.value / 100
                cell.Offset(, 1).value = GetRate(index, levels)
                cell.Offset(, 2).value = GetRate(index, grades)
            Case 2 ' Level
                index = InStr(Join(levels, ""), cell.value) / Len(Join(levels, ""))
                cell.Offset(, -1).value = index * 100
                cell.Offset(, 1).value = GetRate(index, grades)
            Case 3
                index = InStr(Join(grades, ""), cell.value) / Len(Join(grades, ""))
                cell.Offset(, -2).value = index * 100
                cell.Offset(, -1).value = GetRate(index, levels)
        End Select
    Next
End Sub

Function GetRate(index As Double, rates As Variant)
    GetRate = rates(WorksheetFunction.Max(Round(index * (UBound(rates) - LBound(rates) + 1), 0) - 1, 0))
End Function

due to the simplicity of the translation algorithm it doesn't provide a bijective relationship between grading systems with different spans, but it can get you closer to your goal




回答2:


Create a table like so (you can add more rows if you need to define +/- scores like "B+", etc.). The key here is sort the table ascending by %, with each row being the minimum score needed for the corresponding Level/Letter Grade.

Then, you can use VLOOKUP formula against this table, like so to get the Level:

=VLOOKUP(F2,$A$1:$C$7,2,TRUE)

And like so, to get the Letter Grade:

=VLOOKUP(F2,$A$1:$C$7,3,TRUE)

This takes advantage of the True parameter in the VLOOKUP function, which will return an approximate match (and assumes data is sorted ascending). So, when you enter a value like "81%", it returns the nearest row which is not greater than 81%, so it will return data from row 5. Likewise, 12% will return data from row 2, 75% from row 4, etc.

And your results:

You may need to use two tables if you can't 1:1 map the Level/Letter Grade to a Percent row, but the idea would be the same.



来源:https://stackoverflow.com/questions/41600738/excel-multiple-cell-calculation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!