在Excel 2013中使用VBA复制和粘贴时出现问题 [英] Problem with copying and pasting with VBA in Excel 2013
问题描述
我正在尝试处理大量的大文件,需要将公式从一个单元格区域复制/粘贴到另一个单元格。我使用的代码是:
I'm attempting to process a large number of large files and need to copy/paste formulas from one range of cells to another. The code I'm using is this:
范围("I12:P12")。选择
Selection.Copy
对于i = 13至3000
ActiveCell.Offset(1,0)。选择
ActiveSheet.Paste
下一步
Range("I12:P12").Select
Selection.Copy
For i = 13 To 3000
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Next
当我运行代码时,程序将公式粘贴到另一个打开的工作簿的相应单元格中,而不是将复制的公式粘贴到目标单元格中。我在Excel 2010中编写了代码并且工作正常。原始代码更简单。
而不是For ... Next结构,我能够使用一条毯子范围声明选择目标单元格:
When I run the code, instead of pasting the copied formulas into the destination cells, the program pastes the formulas into the corresponding cells of ANOTHER open workbook. I wrote the code in Excel 2010 and it worked fine. The original code was much simpler. Rather than the For...Next structure, I was able to select the destination cells using a blanket range statement:
范围("A1:A3000")。选择
ActiveSheet.Paste
Range("A1:A3000").Select
ActiveSheet.Paste
当我在Excel 2013上运行它时,它开始表现不佳。
When I ran it on Excel 2013 it began behaving badly.
我需要打开其他工作簿,因为它为正在执行的代码提供输入。但是,没有用于写入其他打开的工作簿的代码。唯一的复制位置是活动工作簿中的活动工作表。
I need the other workbook open as it provides inputs to the code that is being executed. There is, however, no code for writing to the other open workbook. The only copy location is the active worksheet in the active workbook.
有什么想法吗?
推荐答案
在修复问题的另一个线程中找到了解决方案。使用Selection.PasteSpecial xlPasteAll。不过,最初的问题仍然存在。为什么ActiveSheet.Paste没有工作?
Found a solution in another thread that fixed the problem. Using Selection.PasteSpecial xlPasteAll. Still, the original question remains. Why doesn't ActiveSheet.Paste work?
这篇关于在Excel 2013中使用VBA复制和粘贴时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!