gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 20:41:36 29 4
gpt4 key购买 nike

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

但我收到一条错误消息:

"Wrong no. of arguments or invalid property assignment"


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

最佳答案

您只需输入左上单元格右下单元格定义一个范围 ,因此您的代码将如下所示:

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

关于vba - 复制和粘贴多个单元格错误 450,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31916270/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com