我创建了一个Excel
/ VBA
函数来计算具有以下功能的学生分数:
一切正常但,问题是:
在工作表上更改值时,它不会自动更新。
需要使用 Ctrl + Alt + F9 或编辑( F2 ),然后按 Enter
请尊敬的专家帮助我。
Function RSLT_N(r1 As Range, r2 As Range, Num As Integer, Level As Integer, Optional Calc_Type As Boolean = False)
Dim i As Byte
If Level = 1 Then
i = 40
ElseIf Level = 2 Then
i = 45
Else
RSLT_N = "Error"
' Exit Function
GoTo L1
End If
Dim cell1 As Range, cell2 As Range, cell3 As Range, cell4 As Range
Dim Rng1 As Range, Rng2 As Range
Set cell1 = Cells(r1.Row, r1.Column)
Set cell2 = Cells(r1.Row, r1.Column + Num - 1)
Set cell3 = Cells(r2.Row, r2.Column)
Set cell4 = Cells(r2.Row, r2.Column + Num - 1)
Set Rng2 = Range(cell3, cell4)
Set Rng1 = Range(cell1, cell2)
With WorksheetFunction
If Check_Left(Rng1) Then
RSLT_N = "Left"
GoTo L1
ElseIf .CountBlank(Rng1) = Num Then
RSLT_N = "-"
ElseIf .Count(Rng1) < Num Then
RSLT_N = "RL"
GoTo L1
Else
For c = 1 To Num
If Rng1.Cells(1, c) / Rng2.Cells(1, c) * 100 < i Then
RSLT_N = "RL"
GoTo L1
End If
Next
If Calc_Type = True Then
RSLT_N = .Subtotal(109, Rng1)
GoTo L1
ElseIf Calc_Type = False Then
RSLT_N = .Sum(Rng1)
GoTo L1
Else
RSLT_N = "Error"
GoTo L1
End If
End If
End With
L1:
End Function
Function Check_Left(Rng As Range)
Dim strTextString, Str As String
Dim btCount As Byte
btCount = Rng.Cells.Count
For c = 1 To btCount
On Error GoTo Last
Set cl = Rng.Cells(1, c)
strTextString = strTextString & cl
Next
With WorksheetFunction
On Error GoTo Last
Str = .IsNumber(.Search("left", strTextString))
End With
Check_Left = True
Exit Function
Last: Check_Left = False
End Function
答案 0 :(得分:0)
您是否尝试过插入代码:
application.calculatefull
希望它适合你。
安德烈
P.S。我忘了提一下,有一些计算方法:
F9 - 重新计算
Application.Calculate
CTRL / ALT / F9 - 完整计算
在Excel 2000/2002/2003中:
Application.CalculateFull
Shift F9 - Sheet Recalculate
Worksheets(“SheetName”).Calculate
范围计算
Range(“$a$1:$d$10”).Calculate
(我认为现在这是一个更完整的答案)