2

我收到类型不匹配 13 错误,我看不到它在哪里。

这是代码。

Set concRange = Range(Cells(11, 48), Cells((10 + noDilutions), 48))
Set deadRange = Range(Cells(11, 49), Cells((10 + noDilutions), 49))
analysisSheet.Cells(f, 14).Value = _
    (WorksheetFunction.Lookup(WorksheetFunction.Index(deadRange, _
    WorksheetFunction.CountIf(deadRange, " >= " & _
    (WorksheetFunction.Max(deadRange) / 2))), deadRange, concRange)) _
    - (((WorksheetFunction.Index(deadRange, WorksheetFunction.CountIf _
    (deadRange, " >= " & (WorksheetFunction.Max(deadRange) / 2)))) _
    - (WorksheetFunction.Max(deadRange) / 2)) * ((WorksheetFunction.Lookup _
    (WorksheetFunction.Index(deadRange, WorksheetFunction.CountIf(deadRange, _
    " >= " & (WorksheetFunction.Max(deadRange) / 2))), deadRange, concRange)) _
    - (WorksheetFunction.Lookup(WorksheetFunction.Index(deadRange, _
    WorksheetFunction.CountIf(deadRange, " <= " & _
    (WorksheetFunction.Max(deadRange) / 2))), deadRange, concRange))) _
    / ((WorksheetFunction.Index(deadRange, WorksheetFunction.CountIf(deadRange, _
    " >= " & (WorksheetFunction.Max(deadRange) / 2)))) _
    - (WorksheetFunction.Index(deadRange, WorksheetFunction.CountIf _
    (deadRange, " <= " & (WorksheetFunction.Max(deadRange) / 2))))))

我尝试将“WorksheetFunction”更改为“Application”和“Application.WorksheetFunction”。

是的,这是一个非常长的公式:D

谁能帮我吗?

4

1 回答 1

9

首先,编写这样的公式是一个非常糟糕的主意,主要有以下三个原因:

  • 几乎无法理解
  • 几乎不可能调试
  • 它重复许多计算=低效

重构,变成

With WorksheetFunction
    A = .Max(deadRange)
    B = .CountIf(deadRange, " >= " & (A / 2))
    C = .CountIf(deadRange, " <= " & (A / 2))
    D = .Index(deadRange, B)
    E = .Index(deadRange, C)
    F = .Lookup(D, deadRange, concRange)
    G = .Lookup(E, deadRange, concRange)

    analysisSheet.Cells(ff, 14).Value = _
        F - ((D - (A / 2)) * (F - G) / (D - E))
End With

调试它揭示了问题:spaces周围>=.CountIf(deadRange, " >= " & (A / 2))错误的原因。

所以,改用

    B = .CountIf(deadRange, ">=" & (A / 2))
    C = .CountIf(deadRange, "<=" & (A / 2))
于 2012-07-14T07:06:35.830 回答