[英]Excel vba syntax error formula value
I'm trying to populate a table with formula but I could not get the last line to wok.我正在尝试用公式填充表格,但我无法获得最后一行。 The first row to be completed for column P is 11, then depending on the number of rows (fyrowCount) to be populated, I want it to increase by 1 each time.
P列要完成的第一行是11,然后根据要填充的行数(fyrowCount),我希望它每次增加1。
If i use the following formula, it works but can't figure out the correct syntax in vba.如果我使用以下公式,它可以工作,但无法找出 vba 中的正确语法。
Formula =IFERROR(INDIRECT("'"&[Item ID'#]&"'!$P$" & 11), "")
公式
=IFERROR(INDIRECT("'"&[Item ID'#]&"'!$P$" & 11), "")
Application.AutoCorrect.AutoFillFormulasInLists = False
If WorksheetFunction.CountA(Range("Table35[Item ID'#]")) = 0 Then
'Range is empty!
For y = 2 To fyrowCount + 1
Range("A" & y).Select
Z = 9 + y
Cells(ActiveCell.Row, 1) = wsName
Cells(ActiveCell.Row, 2).Value = "=IFERROR(INDIRECT(""'""&[Item ID'#]&""'!$G$7""), """")"
Cells(ActiveCell.Row, 3).Value = "=IFERROR(INDIRECT(""'""&[Item ID'#]&""'!$G$6""), """")"
Cells(ActiveCell.Row, 4).Value = "=IFERROR(INDIRECT(""'""&[Item ID'#]&""'!$G$8""), """")"
Cells(ActiveCell.Row, 5).Value = "=IFERROR(INDIRECT(""'""&[Item ID'#]&""'!$G$9""), """")"
Cells(ActiveCell.Row, 6).Value = "=IFERROR(INDIRECT(""'""&[Item ID'#]&""'!$P$"" & z), """")"
Next y
End If
Swap Value
for Formula
like so: Cells(ActiveCell.Row, 2).Formula =
像这样交换
Formula
Value
: Cells(ActiveCell.Row, 2).Formula =
On a seperate note, none of your Range
or Cells
objects are qualified with a worksheet.另请注意,您的
Range
或Cells
对象均不符合工作表的要求。 This can be problematic.这可能有问题。 I highly recomend explicity stating where these objects are.
我强烈建议明确说明这些对象的位置。 (
Sheets("x").Cells(y, 1) = wsName
). (
Sheets("x").Cells(y, 1) = wsName
)。
Also, you do not need to .Select
a cell here as seen below.此外,你并不需要
.Select
这里,如下所示细胞。
Application.AutoCorrect.AutoFillFormulasInLists = False
If WorksheetFunction.CountA(Range("Table35[Item ID'#]")) = 0 Then
For y = 2 To fyrowCount + 1
Z = 9 + y
Cells(y, 1) = wsName
Cells(y, 2).Formula = "=IFERROR(INDIRECT(""'""&[Item ID'#]&""'!$G$7""), """")"
Cells(y, 3).Formula = "=IFERROR(INDIRECT(""'""&[Item ID'#]&""'!$G$6""), """")"
Cells(y, 4).Formula = "=IFERROR(INDIRECT(""'""&[Item ID'#]&""'!$G$8""), """")"
Cells(y, 5).Formula = "=IFERROR(INDIRECT(""'""&[Item ID'#]&""'!$G$9""), """")"
Cells(y, 6).Formula = "=IFERROR(INDIRECT(""'""&[Item ID'#]&""'!$P$"" & z "), """")"
Next y
End If
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.