我的VBA Excel函数在被测试函数调用时可以工作,但是从工作表中调用嵌入到单元格中的另一个函数时却始终失败

时间:2018-07-16 13:40:02

标签: excel vba

Public Sub addtoMA(dbPrice As Double, dbRow As Double, sh As Worksheet)
Dim s As Long   'for bitshifting the array
Const colstosave = 50
Dim rn As Range, intPrice() As Variant
deActsheet  'stop events and other annoyance
On Error GoTo catch
If dbRow = 0 Then
    'MsgBox "row number missing in addtoma"
    GoTo finally
End If
Set rn = sh.Range("At" & dbRow & ":cQ" & dbRow) 'the row
intPrice() = rn 'the  array
   ' shift elements one position right- e.g. arr 99 moves to arr 100
   For s = colstosave To 2 Step -1
        If intPrice(1, s - 1) <> "" Then
            intPrice(1, s) = intPrice(1, s - 1)
        Else
            intPrice(1, s) = 0
        End If
   Next s
intPrice(1, 1) = dbPrice 'current price

    rn = intPrice() 'store the array

finally:
Set rn = Nothing


  actSheet 'allow events and other annoyance
 Exit Sub
catch:

  'MsgBox Err.Description
  Debug.Print ""
  GoTo finally
End Sub

当我使用以下命令从立即窗口调用时,上面的代码运行完美: addtoMA 5,9,sheetpointer

在集成中,

由作为公式嵌入的函数调用。 接收到的参数是相同的,我对此进行了仔细检查。 rn.rowsrn.columns.count的尺寸与 ubound(intprice,1)ubound(intprice,2

但是每次从表单中调用时都会失败

  

应用程序定义或对象定义的错误

我只能使用数据库,但是我不能被它击败。

有什么想法吗? 它只会为机器人生成一些移动平均值

0 个答案:

没有答案