是否可以应用 IF .. 然后在 VBA 中的数组上?我有以下代码,我在数组 plaga 上应用 For Each 和 If - 计算每个 Interval 的出现次数,但是 VBA 返回“下标超出范围。所以,我想也许我必须以不同的方式制定这个.. .
Option Explicit
Public plaga As Variant
Sub dort()
Dim cMin As Double
Dim cMax As Double
Dim lDer As Long
Dim plaga() As Variant
plaga = Worksheets("Sheet3").Range("A1:A10").Value
Call tri1(plaga)
cMin = WorksheetFunction.Min(plaga)
cMax = WorksheetFunction.Max(plaga)
Dim longInter As Double
longInter = (cMax - cMin) / 3
Dim pla As Variant
Dim lCom As Long
lDer = 2
For Each pla In plaga
If pla < cMin + longInter Then
lCom = 1
Else
For lCom = lDer To 3
If pla < cMin + longInter * lCom Then
lDer = lCom
Exit For
End If
Next
End If
plaga(lCom) = plaga(lCom) + 1
Next
Dim Destination As Range
Set Destination = Worksheets("Sheet3").Range("B1")
Destination.Resize(3, 1).Value = plaga
End Sub