VBA Pastespecial范围

时间:2016-05-12 16:57:09

标签: excel vba excel-vba

这有点令人尴尬,因为我刚刚发布了一个关于复制范围的相关问题,但我遇到的问题是我上一次接触不允许粘贴特殊。

现在我尝试从工作表复制到另一个,我收到一个错误。基线代码来自一个没有问题的工作表,但是这里产生了一个1004 error指向第一个设置行。

Sub Script()
Dim Row As Integer
Dim Col As Integer

Row = Worksheets("Design").Cells(11, 22).Value
Col = Worksheets("Design").Cells(12, 22).Value

  Set varRangeselect1 = Worksheets("Tablecorrected").Range(Cells(2 + 19 * Row, 1 + 19 * Col), Cells(19 + 19 * Row, 18 + Col * 19))
  Set varRangeSelect2 = Worksheets("Scriptsheet").Range(Cells(1, 1), Cells(18, 18))
  varRangeselect1.Copy
  varRangeSelect2.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False


End Sub

1 个答案:

答案 0 :(得分:1)

Findwindow给出了正确的提示,工作代码是:

Sub Script()
Dim Row As Integer
Dim Col As Integer

Row = Worksheets("Design").Cells(11, 22).Value
Col = Worksheets("Design").Cells(12, 22).Value

  Set varRangeselect1 = Worksheets("Tablecorrected").Range(Worksheets("Tablecorrected").Cells(2 + 19 * Row, 1 + 19 * Col), Worksheets("Tablecorrected").Cells(19 + 19 * Row, 18 + Col * 19))
  Set varRangeSelect2 = Worksheets("Scriptsheet").Range(Worksheets("Scriptsheet").Cells(1, 1), Worksheets("Scriptsheet").Cells(18, 18))
  varRangeselect1.Copy
  varRangeSelect2.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False


End Sub

谢谢!