嵌套if

时间:2018-08-16 12:39:06

标签: vba nested-if

任何人都可以在下面给出的代码中指出我在做什么错,我得到的编译错误是,对于每个EndIF,都必须事先有相应的IF THanks:

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

1 个答案:

答案 0 :(得分:6)

罪魁祸首是

var email = 'test@example.com, hello@example.com,mail@example.com';
alert ( (/^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i.test(email)) );

If rng.Cells.Offset(0, -1) = "b" Then total = total + rng.Cells.Value 的语法是

If

OR

If <cond> Then <command>