Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 1004错误-将公式动态分配给一系列单元格_Vba_Excel_Excel 2007_Range_Formula - Fatal编程技术网

Vba 1004错误-将公式动态分配给一系列单元格

Vba 1004错误-将公式动态分配给一系列单元格,vba,excel,excel-2007,range,formula,Vba,Excel,Excel 2007,Range,Formula,我正在尝试动态设置执行宏时输入公式的单元格。这段代码将循环大约10次,每次都有一部分新员工。由部门订购。因此,当循环回到这一点时,第一个单元格将发生变化 我得到这个错误: 对象“\u Global”的方法“Range”失败 这是我的密码: 'Select the top cell in the "%Working" Column Range(Cells(StartTemp, 9)).Select 'Insert the Formula - Billable/(Billable + Unbil

我正在尝试动态设置执行宏时输入公式的单元格。这段代码将循环大约10次,每次都有一部分新员工。由部门订购。因此,当循环回到这一点时,第一个单元格将发生变化

我得到这个错误:

对象“\u Global”的方法“Range”失败

这是我的密码:

'Select the top cell in the "%Working" Column

Range(Cells(StartTemp, 9)).Select

'Insert the Formula - Billable/(Billable + Unbillable) * 100 into Column I for each section
'Formula is 'C4/(C4+C5)*100

Range(Cells(StartTemp, 9)).Formula = "=RC[-6]/(RC[-6]+RC[-5]) *100" 
Range(Cells(StartTemp, 9)).Select
Selection.NumberFormat = "0.00%"

'Insert the Formula into all cells in the section for this group.

Selection.AutoFill Destination:=Range(Cells(StartTemp, 9), Cells(EndTemp, 9)), Type:=xlFillDefault    

Range(Cells(StartTemp, 9), Cells(EndTemp, 9)).Select

提前谢谢

由于您使用的是范围(单元格(StartTemp,9))

当将
范围
单元格
一起使用时,不能仅使用一个单元格。语法是

范围(单元格1、单元格2)

这将给您带来一个错误:)

同时避免使用
。选择
。它们也是错误的主要原因

将代码更改为此,然后重试(未经测试


现在试一试。

由于您使用的是
范围(单元格(StartTemp,9))

当将
范围
单元格
一起使用时,不能仅使用一个单元格。语法是

范围(单元格1、单元格2)

这将给您带来一个错误:)

同时避免使用
。选择
。它们也是错误的主要原因

将代码更改为此,然后重试(未经测试


现在试一试。

抛出错误的是哪一行?错误消息的文本是什么?(1004至少有两个不同的行)。抛出错误的是哪一行?错误消息的文本是什么?(1004至少有两个不同的版本)。+1像往常一样解释得很好@JasonR,你也可以摆脱自动填充:
带范围(单元格(StartTemp,9),单元格(EndTemp,9)).Formula=“=RC[-6]/(RC[-6]+RC[-5])*100.NumberFormat=“0.00%”以
结尾谢谢Sam:)我记得你上次也提出过这个建议。这一次我没想到。现在每当我看到自动填充时,我都会想起你:)太棒了,谢谢大家的输入。我已经做了一些调整,现在对我来说效果很好。再次感谢@JasonR:记得在结束问题时选择相关的帖子作为答案:)+1一如既往的好解释@JasonR,你也可以摆脱自动填充:
带范围(单元格(StartTemp,9),单元格(EndTemp,9)).Formula=“=RC[-6]/(RC[-6]+RC[-5])*100.NumberFormat=“0.00%”以
结尾谢谢Sam:)我记得你上次也提出过这个建议。这一次我没想到。现在每当我看到自动填充时,我都会想起你:)太棒了,谢谢大家的输入。我已经做了一些调整,现在对我来说效果很好。再次感谢@JasonR:记住选择相关帖子作为答案来结束问题:)
Msgbox Range(Cells(1, 1)).Address 
With Cells(StartTemp, 9)
    .Formula = "=RC[-6]/(RC[-6]+RC[-5]) * 100"
    .NumberFormat = "0.00%"
    .AutoFill Destination:=Range(Cells(StartTemp, 9), Cells(EndTemp, 9)), Type:=xlFillDefault
End With