gpt4 book ai didi

excel - 为什么我收到 "object does not support this property method"?

转载 作者:行者123 更新时间:2023-12-03 02:20:42 26 4
gpt4 key购买 nike

我在工作簿 Wb1 中的大量工作表中都有信息,并且此信息始终在 F11:F500 范围内。我想将此信息传输到工作簿 Wb A 列中的一张工作表中。请参阅下面的代码。我收到错误在这一行 rng2.Paste

Option Explicit
Sub NameRisk()

' Copy and paste

Dim wb1 As Workbook
Dim wb As Workbook
Dim ws As Worksheet
Dim ws1 As Worksheet
Dim rng As Range
Dim c As Range
Dim lastrow As Long
Dim rng2 As Range

Set wb1 = Application.Workbooks("COMBINED ADD.xls")
Set wb = Application.Workbooks("NameRiskXtract.xlsm")

Set ws = wb.Worksheets("Sheet1")


For Each ws1 In wb1.Sheets
Set rng = Range("F11:F500")
For Each c In rng
If c.Value <> "" Then
c.Copy
With ws
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
Set rng2 = ws.Range("A" & lastrow)
rng2.Paste
End With
End If
Next c
Next ws1
End Sub

最佳答案

Range("F11:F500") 应该有一个父工作表;我猜它是ws1。您可能正在取消复制操作。更好地复制目的地。

...
For Each ws1 In wb1.Sheets
Set rng = ws1.Range("F11:F500")
For Each c In rng
If c.Value <> "" Then
c.Copy destination:=ws.Cells(ws.Rows.Count, "A").End(xlUp).offset(1, 0)
End If
Next c
Next ws
...

关于excel - 为什么我收到 "object does not support this property method"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53064588/

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