请允许任何人指出我在下面给出的代码中做了什么错误,我得到编译错误,对于每个EndIF,必须提前对应的IF THank:
Public Function customavg(rng As Range, nr_weeks As Integer)
Dim total As Integer, count_rng_row As Integer, count_wk As Integer, counter_rng As Integer
total = 0
count_rng_row = rng.Rows.count
count_wk = 0
counter_rng = count_rng_row
For counter_rng = count_rng_row To 1
If count_wk < nr_weeks Then
If rng.Cells.Offset(0, -1) = "b" Then total = total + rng.Cells.Value
counter_rng = counter_rng - 1
count_wk = count_wk + 1
End If
'Else
' counter_rng = counter_rng - 0
' count_wk = count_wk + 0
End If
Next counter_rng
customavg = total / nr_weeks
End Function
Run Code Online (Sandbox Code Playgroud)
罪魁祸首是
If rng.Cells.Offset(0, -1) = "b" Then total = total + rng.Cells.Value
Run Code Online (Sandbox Code Playgroud)
语法If是
If <cond> Then <command>
Run Code Online (Sandbox Code Playgroud)
要么
If <cond> Then
<commands>
End If
Run Code Online (Sandbox Code Playgroud)