代码不单独填充 Table 个单元格,而是填充整列
Code Not Filling Table Cells Individually, Filling Whole Columns Instead
我有一个按钮,可以从列表框中获取数据并将其放入我的 table 的特定单元格中。我现在的问题是,当将值插入单元格时,它会填充该单元格所在的整列,而不是特定的单元格。
这是按钮的代码:
Private Sub cbSubmit_Click()
Dim i As Long
Dim v As Variant
Dim vTable() As Variant
Set inventoryTable = cSheet.ListObjects("inventory_table")
colItemID = inventoryTable.ListColumns("Item #").Index
colSpecs = inventoryTable.ListColumns("Specs").Index
v = inventoryTable.DataBodyRange.Rows
ReDim vTable(1 To UBound(v, 1), 1 To 4)
For i = 0 To lbItemList.ListCount - 1
vTable(i + 1, 1) = "=DATA!" & lbItemList.List(i, 2)
If specLink = "" Then
Exit For
Else
vTable(i + 1, 4) = lbItemList.List(i, 1)
End If
inventoryTable.DataBodyRange(i + 1, colItemID).Value = vTable(i + 1, 1)
inventoryTable.DataBodyRange(i + 1, colSpecs).Value = vTable(i + 1, 4)
Next
Unload Me
End Sub
这是我 运行 按钮后的样子。
我希望它只填充 Item # 中的第一个单元格,然后是同一行中 Specs 中的单元格。然后沿着每个单元格的行向下并填写下一个项目。相反,每个项目都被填充到旧项目之上。
如果您要定位结构化 table 中的单个单元格(aka ListObject object) then you need to turn of the AutoCorrect.AutoFillFormulasInLists property。
Application.AutoCorrect.AutoFillFormulasInLists = False
这也可以通过Alt+F,T,[=22来实现=]P, Alt+A 然后转到 键入时自动套用格式选项卡并取消选中 Fill formulas in tables to create calculated columns.
如果您希望此应用程序范围内的选项可用,可选择在子过程结束时将其重新打开。
Application.AutoCorrect.AutoFillFormulasInLists = True
我有一个按钮,可以从列表框中获取数据并将其放入我的 table 的特定单元格中。我现在的问题是,当将值插入单元格时,它会填充该单元格所在的整列,而不是特定的单元格。
这是按钮的代码:
Private Sub cbSubmit_Click()
Dim i As Long
Dim v As Variant
Dim vTable() As Variant
Set inventoryTable = cSheet.ListObjects("inventory_table")
colItemID = inventoryTable.ListColumns("Item #").Index
colSpecs = inventoryTable.ListColumns("Specs").Index
v = inventoryTable.DataBodyRange.Rows
ReDim vTable(1 To UBound(v, 1), 1 To 4)
For i = 0 To lbItemList.ListCount - 1
vTable(i + 1, 1) = "=DATA!" & lbItemList.List(i, 2)
If specLink = "" Then
Exit For
Else
vTable(i + 1, 4) = lbItemList.List(i, 1)
End If
inventoryTable.DataBodyRange(i + 1, colItemID).Value = vTable(i + 1, 1)
inventoryTable.DataBodyRange(i + 1, colSpecs).Value = vTable(i + 1, 4)
Next
Unload Me
End Sub
这是我 运行 按钮后的样子。
我希望它只填充 Item # 中的第一个单元格,然后是同一行中 Specs 中的单元格。然后沿着每个单元格的行向下并填写下一个项目。相反,每个项目都被填充到旧项目之上。
如果您要定位结构化 table 中的单个单元格(aka ListObject object) then you need to turn of the AutoCorrect.AutoFillFormulasInLists property。
Application.AutoCorrect.AutoFillFormulasInLists = False
这也可以通过Alt+F,T,[=22来实现=]P, Alt+A 然后转到 键入时自动套用格式选项卡并取消选中 Fill formulas in tables to create calculated columns.
如果您希望此应用程序范围内的选项可用,可选择在子过程结束时将其重新打开。
Application.AutoCorrect.AutoFillFormulasInLists = True