【发布时间】:2017-04-20 21:22:12
【问题描述】:
我正在尝试添加最后一行,然后将公式放在最后一行的特定单元格中。当我运行我所拥有的内容时,它会将公式添加到 OLD 最后一行,而不是我新创建的那个。你能帮忙吗?
Sub AddDataRow()
Dim tableName As String
Dim sheet As Worksheet
Dim table As ListObject
Dim lastRow As Range
tableName = ActiveSheet.ListObjects(1)
Set sheet = Range(tableName).Parent
Set table = sheet.ListObjects.Item(tableName)
If table.ListRows.Count > 0 Then
Set lastRow = table.ListRows(table.ListRows.Count).Range
If Application.CountBlank(lastRow) < lastRow.Columns.Count Then
table.ListRows.Add
End If
End If
lastRow.Columns("L").Formula = "=A1+B1"
End Sub
【问题讨论】:
标签: excel excel-formula insert row vba