在下一个可用行中添加数据

时间:2016-07-28 08:37:06

标签: excel vba excel-vba range offset

此宏在单元格A10中添加数据。现在,每次再次运行时,数据都会被覆盖。我怎样才能在下面添加1个cel?

Sub Invoer()


Dim Debiteurnummer As Integer
Dim Aantalpallets As Integer
Dim Totaalgewicht As Integer

Debiteurnummer = InputBox("Debiteurnummer invoeren")
Aantalpallets = InputBox("Aantal Pallets?")
Totaalgewicht = InputBox("Totaal Gewicht?")

Range("A10").Value = Debiteurnummer
Range("A10").Offset(0, 2) = Aantalpallets
Range("A10").Offset(0, 3) = Totaalgewicht




End Sub

1 个答案:

答案 0 :(得分:0)

添加 LastRow 的动态搜索:

Sub Invoer()

Dim Debiteurnummer As Integer
Dim Aantalpallets As Integer
Dim Totaalgewicht As Integer
Dim LastRow As Long

Debiteurnummer = InputBox("Debiteurnummer invoeren")
Aantalpallets = InputBox("Aantal Pallets?")
Totaalgewicht = InputBox("Totaal Gewicht?")

LastRow = Cells(Rows.count, "A").End(xlUp).row

Range("A" & LastRow + 1).Value = Debiteurnummer
Range("A" & LastRow + 1).Offset(0, 2) = Aantalpallets
Range("A" & LastRow + 1).Offset(0, 3) = Totaalgewicht

End Sub