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.
If i use the following formula, it works but can't figure out the correct syntax in vba.
Formula =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 =
On a seperate note, none of your Range
or Cells
objects are qualified with a worksheet. This can be problematic. I highly recomend explicity stating where these objects are. ( Sheets("x").Cells(y, 1) = wsName
).
Also, you do not need to .Select
a cell here as seen below.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.