[抱歉,我是VBA的新手。但是,如果条件满足,我将尝试复制单元格值,并将其动态粘贴到电子表格的另一行中。因此,如果单元格值Q13为=“ 45”,则它将将该值粘贴到最后一个活动行的P列中。
Sub Copy_Values()
Dim range1 As Range
Dim Cell As Range
Set range1 = Sheet2.Range("Q13")
For Each Cell In range1
If Cell.Value = "45" Then
With Sheet2
.Cells(Cell.Row, "Q13").Copy Sheet2.Range("P").End(xlUp)
End With
End If
Next
End Sub
以下内容将达到您想要的结果,它将动态获取P列中的下一个空行并将值粘贴到那里:
Sub Copy_Values()
Dim range1 As Range
Dim Cell As Range
Set range1 = Sheet2.Range("Q13")
For Each Cell In range1
If Cell.Value = "45" Then
With Sheet2
NextRow = .Cells(.Rows.Count, "P").End(xlUp).Offset(1, 0).Row
.Cells(Cell.Row, "Q13").Copy Sheet2.Range("P" & NextRow)
End With
End If
Next
End Sub