3

以下は、このエラーをスローしている私のコードです:

RangeクラスのPasteSpecialメソッドが失敗しました

デバッグしようとしているときにのみエラーがスローされます。

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

このエラーを回避する方法はありますか?

4

2 に答える 2

2

私は(上記が実際にあなたの完全なコードである場合)あなたはデータをコピーして直接貼り付けを行おうとしているのではなく、したがってそのエラーが発生していると信じています:)

これはあなたがしようとしていることですか?

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
于 2012-06-04T12:22:07.977 に答える
1

この種のエラーを回避する最善の方法は、完全に修飾された範囲のみを使用することです。

With Sheets("The name of the sheet")
    .Range(.Cells(7, 1), .Cells(RowRange + 7, 2)).PasteSpecial Paste:=xlValues
End With

または:With ActiveSheetシートがすでに選択されていることがわかっている場合。

また、選択する必要はありませんのでご注意ください。

于 2012-06-04T11:37:22.710 に答える