VBA-1004错误-尝试复制到命名范围-VBA的新功能

时间:2019-02-04 17:29:44

标签: excel vba paste named-ranges

VBA的新手,并努力找出我做错了什么-我做不到。我的代码如下。我不断收到运行时错误1004(应用程序定义或对象定义的错误)。

在将单元格值复制到sheet2上的命名范围之前,必须满足两个条件。一切似乎进展顺利,直到我要复制它为止。

非常感谢您的帮助!

Sub MoveHrs()

Dim i As Integer 'Loop
Dim Wb As Workbook, Ws As Worksheet 'Set objects
Set Wb = ThisWorkbook 'workbook
Set Ws = Wb.Worksheets("NDE2018") 'Sheets
Dim Ws2 As Worksheet
Set Ws2 = Wb.Worksheets("Sheet2") '2nd worksheet

'loop through each cell
For i = 24 To Ws.Cells(Ws.Rows.Count, "C").End(xlUp).Row 'from row 24 to last cell with data

    If Ws.Cells(i, 3) > 0 And Ws.Cells(i, 3).Offset(0, -1) = "18liist" Then 'find hours and copy to appropriate named range in ws2
        Ws.Cells(i, 3).Copy Ws2.Range("LIIST18" & Rows.Count).End(xlUp).Row + 1
    ElseIf Ws.Cells(i, 3) > 0 And Ws.Cells(i, 3).Offset(0, -1) = "18liiot" Then 'find hours and copy to appropriate named range in ws2
        Ws.Cells(i, 3).Copy Ws2.Range("LIIOT18" & Rows.Count).End(xlUp).Row + 1

  End If
Next i

Application.CutCopyMode = False 'suppress the marching ants
End Sub

0 个答案:

没有答案