将单元格值设置为double类型的变量时的运行时错误1004

时间:2018-02-16 18:55:42

标签: excel excel-vba excel-2016 vba

我很难理解为什么我会一直收到这个错误。我有以下代码:

Public Var as Double, Rng2 as Range
Option Explicit
Sub Example()
Dim R as Range, Rng as Range
Dim Row as Long
Set Rng = Range("A1", Range("A1").End(xlDown))
SetRanges 'This is a sub routine that scans Row 1 of my Spreadsheet and sets Rng2 to the
'appropriate column. IE I'm looking for Name Change column. As I'm still developing this
'sheet I expect I may end up moving this column at some point. I would like to avoid
'needing to come back into the macro to adjust if possible
For each R in Rng
  Row = R.Row
  If "Logic Statement" then
    Calc 'Calc is a sub in another module that calculates the value of Var which results in
         '0.72658 right now. The reason I pass the variable is because I'm referring to a
         'new workbook with a different set of ranges. 
  Else
    MsgBox "Error Statement"
    Exit Sub
  EndIf
  Rng2.Rows(Row).Value = Var 'This is the line giving me the Runtime Error
Next R
End Sub

我不明白为什么这会给我RunTime Error 1004" Application Defined或Object Defined错误。"我在同一张表中有其他宏做类似的事情。唯一的区别是,我只是通过说Rng2.Rows(Row).Value = DataRng.Rows(DataRow).Value来简单地提取数据,而不是进行计算。我声明我的Var是错误的类型还是其他的东西?

0 个答案:

没有答案