我刚开始使用VBA,我正在尝试复制活动单元格的内容并将其传递到同一页面的另一列。但它一直给我运行时错误。任何建议都会有所帮助。
Option Explicit
Sub copypaste()
Dim lastrow As Long, content As String, i As Integer, numrow As Integer
lastrow = Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row
numrow = ActiveCell.Row
content = ActiveCell.Value
For i = 0 To (lastrow - numrow)
If Sheets("Sheet2").Cells(numrow + i, 1).Value = content Then
Sheets("Sheet2").Cells(numrow + i, 2).copy
Sheets("Sheet2").Cells(2+i, 10).Paste
Application.CutCopyMode = False
End If
Next i
End Sub
给定的运行时错误是对象不支持此属性或方法。任何建议都会有所帮助!感谢
答案 0 :(得分:0)
Try using the value of one cell to another instead of copying
Option Explicit
Sub copypaste()
Dim lastrow As Long, content As String, i As Integer, numrow As Integer
lastrow = Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row
numrow = ActiveCell.Row
content = ActiveCell.Value
For i = 0 To (lastrow - numrow)
If Sheets("Sheet2").Cells(numrow + i, 1).Value = content Then
Sheets("Sheet2").Cells(2+i, 10).Value = Sheets("Sheet2").Cells(numrow + i, 2).Value
End If
Next i
End Sub