VBA通过单元格添加细胞从一张纸到另一张细胞

我想创建按钮,该按钮通过添加的时间将一个单元格从一个纸上添加到另一张纸。在图像中,我展示了我想做什么的示例。 添加第一个单元格

到目前为止,我明白了

Sub CopyBasedonSheet1()Dim i As IntegerDim j As IntegerSheet1LastRow = Worksheets("Sheet1").Range("B" & Rows.Count).End(xlUp).Row i = 1For j = 1 To Sheet1LastRow    If Worksheets("Sheet1").Cells(j, 2).Value = "a" Then        Worksheets("Sheet2").Cells(i, 1).Value = Worksheets("Sheet1").Cells(j, 1).Value        Worksheets("Sheet2").Cells(i, 2).Value = Worksheets("Sheet1").Cells(j, 2).Value        i = i + 1    End IfNext jEnd Sub

但是,当我再次添加下一个单元格时,它将在表2中覆盖整个单元格。我想这样做这样的事情:添加下一个单元格 你能帮助我吗?

您的代码说put sheet1!答:a sheet1!b:b是“ a”,而无视embled eghd1!b:b。我会选择后者。

Option Explicit Sub CopyBasedonSheet1()    Dim j As Long, Sheet1LastRow As Long, Sheet2NextRow As Long          Sheet1LastRow = Worksheets("Sheet1").Range("B" & Rows.Count).End(xlUp).Row    Sheet2NextRow = Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Row + _          IsEmpty(Worksheets("Sheet2").Range("A1"))     With Worksheets("Sheet1")        For j = 1 To Sheet1LastRow            If .Cells(j, "B").Value = "a" And _              IsError(Application.Match(.Cells(j, "A").Value, Worksheets("Sheet2").Columns("A"), 0)) Then                Worksheets("Sheet2").Cells(Sheet2NextRow, "A").Value = .Cells(j, "A").Value                Sheet2NextRow = Sheet2NextRow + 1            End If        Next j    End WithEnd Sub

本文链接:https://xdcnz.com/10648.html