我在一张纸上有这个表格,它有一个带有宏的命令按钮。当我单击它时,它会将 Sheet1 单元格中的所有数据插入到 sheet2 的单行中。我已经放置了下一个空行命令,但我希望所有数据仍然在同一行中,即使前一行是空的。
我使用了以下代码:
Sub Botao()
Dim ws1, ws2 As Worksheet
Dim código, tipo, textobrevematerial, codigopa, textobrevepa, ncm, versão, motivo1, motivo2, motivo3, datarecebimento, _
dataimpressao, datamkt, datarevisor, datasedev, dataar, datart, dataredmkt, dataredsedev As Range
Set ws1 = Worksheets("Plan1")
Set ws2 = Worksheets("Plan2")
Set código = ws2.Cells(Rows.Count, "a").End(xlUp)
Set datarecebimento = ws2.Cells(Rows.Count, "b").End(xlUp)
Set tipo = ws2.Cells(Rows.Count, "c").End(xlUp)
Set textobrevematerial = ws2.Cells(Rows.Count, "d").End(xlUp)
Set codigopa = ws2.Cells(Rows.Count, "e").End(xlUp)
Set textobrevepa = ws2.Cells(Rows.Count, "f").End(xlUp)
Set ncm = ws2.Cells(Rows.Count, "g").End(xlUp)
Set versão = ws2.Cells(Rows.Count, "h").End(xlUp)
Set dataimpressão = ws2.Cells(Rows.Count, "i").End(xlUp)
Set datamkt = ws2.Cells(Rows.Count, "j").End(xlUp)
Set datarevisor = ws2.Cells(Rows.Count, "k").End(xlUp)
Set datasedev = ws2.Cells(Rows.Count, "l").End(xlUp)
Set dataar = ws2.Cells(Rows.Count, "m").End(xlUp)
Set datart = ws2.Cells(Rows.Count, "n").End(xlUp)
Set motivo1 = ws2.Cells(Rows.Count, "o").End(xlUp)
Set motivo2 = ws2.Cells(Rows.Count, "p").End(xlUp)
Set motivo3 = ws2.Cells(Rows.Count, "q").End(xlUp)
Set dataremkt = ws2.Cells(Rows.Count, "r").End(xlUp)
Set dataresedev = ws2.Cells(Rows.Count, "s").End(xlUp)
código.Offset(1, 0) = ws1.Range("d4").Value
datarecebimento.Offset(1, 0) = ws1.Range("H4")
tipo.Offset(1, 0) = ws1.Range("b8")
textobrevematerial.Offset(1, 0) = ws1.Range("D8")
codigopa.Offset(1, 0) = ws1.Range("B12")
textobrevepa.Offset(1, 0) = ws1.Range("D12")
ncm.Offset(1, 0) = ws1.Range("B16")
versão.Offset(1, 0) = ws1.Range("D16")
dataimpressão.Offset(1, 0) = ws1.Range("F18")
datamkt.Offset(1, 0) = ws1.Range("F20")
datarevisor.Offset(1, 0) = ws1.Range("F22")
datasedev.Offset(1, 0) = ws1.Range("M18")
dataar.Offset(1, 0) = ws1.Range("M20")
datart.Offset(1, 0) = ws1.Range("m22")
motivo1.Offset(1, 0) = ws1.Range("B26")
motivo2.Offset(1, 0) = ws1.Range("B30")
motivo3.Offset(1, 0) = ws1.Range("B32")
dataremkt.Offset(1, 0) = ws1.Range("F38")
dataresedev.Offset(1, 0) = ws1.Range("M38")
End Sub
那么即使前一行包含一个空单元格,我应该使用什么代码将所有代码插入同一行?