简体   繁体   English

使用VBA-Excel将公式写入单元格时出现1004错误

[英]1004 error when writing a formula to a cell using VBA-Excel

I am trying to write a formula into a cell, using VBA. 我正在尝试使用VBA将公式写入单元格。 The code excerpt below delivers the correct formula, with correct references. 下面的代码摘录提供了正确的公式以及正确的引用。 But I keep getting a 1004 run-time error. 但是我一直收到1004运行时错误。 I can't figure out what is triggering it. 我不知道是什么触发了它。 Hope this code excerpt is enough to reveal the answer, but if you need more just ask. 希望这段代码摘录足以揭示答案,但是如果您需要更多内容,请询问。

 Set rg_sheet = ActiveWorkbook.Worksheets("RUNGLANCE")
  for colNo = 2 to 8
   for rowNo = 3 to 27
     daySheetName = Cells(1,colNo)
     rg_sheet.cells(rowNo,ColNo).formula = "=VLookUp(" & Chr(34) & "$A" & rowNo & Chr(34) & "), " & daySheetName & "!(" & chr(34) & "$A$3:$B$27" & Chr(34) & ", 2, False"
   next rowNo
  next colNo

Instead of 代替

rg_sheet.cells(rowNo,ColNo).formula = "=VLookUp(" & Chr(34) & "$A" & rowNo & Chr(34) & "), " & daySheetName & "!(" & chr(34) & "$A$3:$B$27" & Chr(34) & ", 2, False"

try 尝试

rg_sheet.Cells(rowNo, colNo).Formula = "=VLookUp($A" & rowNo & ", " & daySheetName & "!" & "$A$3:$B$27" & ", 2, False" & ")"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM