gpt4 book ai didi

excel - Excel 2010 中出现错误,Range 类的 PasteSpecial 方法在宏内失败

转载 作者:行者123 更新时间:2023-12-02 18:45:29 24 4
gpt4 key购买 nike

以下是我的代码,抛出此错误:

PasteSpecial method of Range class failed

仅当我尝试调试时才会抛出错误。

Range(Cells(7, 1), Cells((Rowrange + 7), 2)).Select
Selection.PasteSpecial Paste:=xlValues


' my complete code

strSheetName = "sheet1"
Sheets(strSheetName).Select
B6 = Range("B6").Value
B7 = Range("B7").Value
Range(Cells(11, 1), Cells((Rowrange + 11), 2)).Select
Selection.Copy

strSheetName = "sheet2"
Sheets(strSheetName).Select
' Range(Cells(7, 1), Cells((Rowrange + 7), 2)).Select
'.Range(Cells(7,1), .Cells(RowRange + 7, 2). PasteSpecial Paste := xlValues
'Selection.PasteSpecial Paste:=xlValues
With ActiveSheet
.Range(.Cells(7, 1), .Cells(Rowrange + 7, 2)).PasteSpecial Paste:=xlValues
End With

有办法避免这个错误吗?

最佳答案

我相信(如果上面实际上是您的完整代码)您没有复制数据并直接尝试进行粘贴,因此您会收到该错误:)

这就是你正在尝试的吗?

strSheetName = "Estimated vs Actual Costs"
With Sheets(strSheetName)
.Range(.Cells(7, 1), .Cells(RowRange + 7, 2)).Copy
.Range(.Cells(7, 1), .Cells(RowRange + 7, 2)).PasteSpecial Paste:=xlValues
End With

跟进

试试这个

strSheetName = "sheet1"
With Sheets(strSheetName)
B6 = .Range("B6").Value
B7 = .Range("B7").Value
.Range(.Cells(11, 1), .Cells((RowRange + 11), 2)).Copy
End With

strSheetName = "sheet2"
With Sheets(strSheetName)
.Range(.Cells(7, 1), .Cells(RowRange + 7, 2)).PasteSpecial Paste:=xlValues
End With

关于excel - Excel 2010 中出现错误,Range 类的 PasteSpecial 方法在宏内失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10880007/

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