复制和粘贴多个单元格错误450

时间:2015-08-10 09:40:39

标签: excel vba excel-vba

我正在尝试根据特定条件将多个单元格复制到新工作表。

但我收到一个错误说:

  

“错误的参数或无效的属性赋值”

Sub sort()

Set ws = ThisWorkbook.Sheets(Array("3rd and 4th Floor Columns", "3rd Floor Beams", "Test1", "Test2"))


For k = 12 To 360
With ws(1)
i = 1
j = 1
 Select Case ws(1).Cells(k, 9).Value

 Case 26

 ws(1).Range(.Cells(k, 9), .Cells(k, 12)).Copy
 ws(3).Range(.Cells(i, 1), .Cells(i, 4)).PasteSpecial xlPasteValues

 Application.CutCopyMode = False
 i = i + 1

 Case 57

 ws(1).Range(.Cells(k, 9), .Cells(k, 12)).Copy
 ws(4).Range(.Cells(j, 1), .Cells(j, 4)).PasteSpecial xlPasteValues 'Application defined.. error

 Application.CutCopyMode = False
 j = j + 1

Case Else

End Select
End With
Next k
End Sub

1 个答案:

答案 0 :(得分:1)

您只需要将左上角的单元格右下角的单元格输入定义范围,这样您的代码就会显示为:

For k = 12 To 360
With ws(1)
    i = 1
    j = 1
    Select Case .Cells(k, 9).Value
        Case 26
            ws(1).Range(.Cells(k, 9), .Cells(k, 12)).Copy
            ws(3).Range(ws(3).Cells(i, 1)).PasteSpecial Paste:=xlPasteValues
            Application.CutCopyMode = False
            i = i + 1
        Case 57
            ws(1).Range(.Cells(k, 9), .Cells(k, 12)).Copy
            ws(4).Range(ws(4).Cells(j, 1)).PasteSpecial Paste:=xlPasteValues
            Application.CutCopyMode = False
            j = j + 1
        Case Else
    End Select
End With