excel - 添加项目后VBA删除行
问题描述
我希望删除添加的项目下方的行,因为一旦我单击确认销售并想添加更多项目。添加的项目将直接替换“总计”、“gst”等行。我可以知道我该怎么做吗?
这是我添加购物车的代码:
Sub addcart()
Dim lastrow As Long
Dim i As Integer, j As Integer, k As Integer, m As Integer
lastrow = Sheets("Sales Point").Range("E" & Rows.Count).End(xlUp).Row
If Range("C6").Value = 0 = False And IsEmpty(Range("C6").Value) = False Then
'Number of item
For i = 5 To lastrow + 1
Cells(i, 5).Value = i - 4
Next
Cells(lastrow + 1, 6) = Range("C4") 'Item code
Cells(lastrow + 1, 7) = Range("C3") 'Item Name
Cells(lastrow + 1, 8) = Range("C6") 'Quantity
Cells(lastrow + 1, 9) = Format(Range("C5"), "$#,##.00#") 'Unit Price
Cells(lastrow + 1, 10) = Format(Cells(lastrow + 1, 9) * Cells(lastrow + 1, 8), "$#,##.00#") 'Total
Else
MsgBox "Error Message!!!"
End If
End Sub
解决方案
那这个呢:
Range("A" & (LastRow + 1)).Offset(1,0).EntireRow.Delete
解释:
- 我相信最后一行等于
LastRow + 1
? Offset(1,0)
是下一行的单元格。EntireRow.Delete
很明显。
推荐阅读
- python - 当我写入与以前删除的文件具有相同文件名的文件时,scipy.io.wavfile.write 不起作用
- html - 为什么这个 CSS 代码让我的下拉菜单只显示 3 中的一项?
- javascript - 仅使用 CSS 单击时更改不同按钮的背景和字体颜色。我试过 :focus 但只适用于 Chrome
- mercurial - 如何在 tortoisehg 中变基?
- javascript - 如果找不到 ID (document.getElementById),希望 JS 继续
- angular - 从控制台触发 router.navigate
- batch-file - 如何修复批量无法正确加载网站链接?
- gatsby - 如何使用 Gatsby 制作的网站对 Strapi 中的数据进行变异?
- python - 如何创建仅在图像中显示黑色的白色蒙版?
- python - 如何查询扳手并获取元数据,尤其是列名?