Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 粘贴整行时出现问题_Excel_Vba - Fatal编程技术网

Excel 粘贴整行时出现问题

Excel 粘贴整行时出现问题,excel,vba,Excel,Vba,我正在尝试将enire信息行粘贴到下一个可用行,但我不断遇到错误,原因是行(lastrow+1,1).EntireRow.paste写得不正确。请让我知道如何正确执行该操作 Private Sub CommandButton1_Click() Dim myValue As String myEmp = InputBox("Search for an employee by last name") Range("B3").Value = myEmp With Sheet

我正在尝试将enire信息行粘贴到下一个可用行,但我不断遇到错误,原因是
行(lastrow+1,1).EntireRow.paste
写得不正确。请让我知道如何正确执行该操作

Private Sub CommandButton1_Click()

    Dim myValue As String
    myEmp = InputBox("Search for an employee by last name")
    Range("B3").Value = myEmp

With Sheet7
    Range("B:B").Select
        Set Row = Selection.Find(What:=myEmp, After:=ActiveCell, _
        LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
        SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    Row.EntireRow.Copy

End With

Worksheets("Employee Reports").Activate
    Dim lastrow As Long
    lastrow = Range("A65536").End(xlUp).Row
    Rows(lastrow + 1, 1).EntireRow.Paste


End Sub
Private Sub Workbook_Open()

Application.EnableEvents = False
Worksheets("Sheet3").Range("A4:A20").Value = ""

End Sub

Rows(lastrow+1,1).EntireRow.PasteSpecial
当我运行该行时,我得到运行时错误“1004”:该行的应用程序定义或对象定义错误当我这样做时,它给了我运行时错误“438”:对象不支持此属性或方法
单元格(lastrow+1,1).PasteSpecial
我复制并粘贴了它,现在我得到了运行时错误“9”:下标超出了
lastrow=Worksheets(“Employee Reports”).range(“A65536”).End(xlUp)。Row
@Tara则没有名为
Employee Reports
的工作表,请检查以确保其拼写正确,并且工作表名称中没有前导空格或结束空格。是的,小错误。现在它给出了运行类型错误“13”:Set rw=.Range(“B:B”)的类型不匹配。Find(What:=myEmp,After:=ActiveCell,LookIn:=xlFormulas,LookAt:=xlother,SearchOrder:=xlByRows,SearchDirection:=xlNext,MatchCase:=False,SearchFormat:=False)将删除我的答案,因为Scott找到了我正在处理的两件事。。。语法不正确(改为使用
单元格()
),并一个接一个地直接复制/粘贴,以防止剪贴板清除副本。@ScottCraner我刚才也看到了你对
.paste
的评论,在回答时错过了对
.pastespecial
的更改
Private Sub CommandButton1_Click()

    Dim myValue As String
    myEmp = InputBox("Search for an employee by last name")
    ActiveSheet.Range("B3").Value = myEmp

    Dim lastrow As Long
    lastrow = Worksheets("Employee Reports").Range("A65536").End(xlUp).Row

    With Sheet7
        Dim rw As Range
        Set rw = .Range("B:B").Find(What:=myEmp, After:=.Range("B1"), _
        LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
        SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)

        If Not rw Is Nothing Then
            rw.EntireRow.Copy Worksheets("Employee Reports").Cells(lastrow + 1, 1)
        Else
            MsgBox myEmp & " Not Found in Range"
        End If
    End With
End Sub