使用PasteValues运行到Error – 1004'应用程序定义的或对象定义的错误'
运行到错误1004试图复制和粘贴单元格值(消除公式,只是获取值)。 当我把它logging在工作表上的时候工作的很好,但是当我在我的子程序中执行它的时候它不起作用。 PasteSpecial
行上发生错误:
If i = ws_count Then 'ws_count - 2 allows us to place the new tab before the last sheet in the data file (admin) Sheets(twomonthsago).Copy Before:=Sheets(ws_count - 2) Sheets(twomonthsago & " (2)").Name = lastmonth & " test" Sheets(twomonthsago).Cells.Copy Sheets(twomonthsago).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False End If
我也尝试直接selectRange("A1")
粘贴之前,仍然得到错误。 我所有的variables都有有效的string分配给他们,所以这不是问题。
直接分配。
replace这些:
Sheets(twomonthsago).Cells.Copy Sheets(twomonthsago).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
附:
With Sheets(twomonthsago).UsedRange .Value = .Value End With