2014-01-10 66 views
0

我有一个VBA脚本,它结合了一堆Excel文件中的数据并整齐地呈现结果。 它通过打开一个输入文件,复制所需的数据范围并将其粘贴到结果文件中来反复进行。在Excel 2013中粘贴错误VBA

我们只是升级到Office 2013,以及一些膏是要在错误的位置,例如:

Workbooks(currentBook).Sheets("InputList").Range("E1:F1000").Copy 
    ThisWorkbook.Sheets("Results").Range("B2").PasteSpecial Paste:=xlPasteValuesAndNumberFormats 

不粘贴到单元格B2而是J1。

Location Date Value 
Location Date Value 
Location Date Value 

通过执行以下代码:

应该给另一个复制粘贴操作

Workbooks(currentBook).Sheets("Pay").Range("B1:B2").Copy 
ThisWorkbook.Sheets("Problem Sheets").Range("E1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats 
ThisWorkbook.Sheets("Problem Sheets").Range("E1:E2").Copy 
ThisWorkbook.Sheets("Problem Sheets").Range("A" & problemCell).PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Transpose:=True 
ThisWorkbook.Sheets("Problem Sheets").Range("E1:E2").ClearContents 
problemCell = problemCell + 1 

是不是结束了:

Location Location Value 
Location Location Value 
Blank  Blank  Value 

我真的很感激任何帮助理解和处理这种行为 - 我需要能够相信结果s文件,在Office 2010中我可以!

回答

0

此问题可通过在需要的范围循环,分配每个目的地小区的值等于要被校正原始单元格的值如下所示:

For copyCount = 1 To 1000 
    ThisWorkbook.Sheets("Pay").Cells(copyCount + 1, 2).Value = _ 
     Workbooks(currentBook).Sheets("Employee List").Cells(copyCount, 5).Value 
    ThisWorkbook.Sheets("Pay").Cells(copyCount + 1, 3).Value = _ 
     Workbooks(currentBook).Sheets("Employee List").Cells(copyCount, 6).Value 
    ThisWorkbook.Sheets("Pay").Cells(copyCount + 1, 1).Value = _ 
     Workbooks(currentBook).Sheets("Employee List").Cells(copyCount, 7).Value 
Next 

虽然这可以解决遇到的复制和粘贴功能问题,但它并不能解释错误的起因,所以我仍然对任何与此有关的答案感兴趣。

1

替换:

ThisWorkbook.Sheets("Results").Cells("B2").PasteSpecial Paste:=xlPasteValuesAndNumberFormats 

ThisWorkbook.Sheets("Results").Range("B2").PasteSpecial Paste:=xlPasteValuesAndNumberFormats 

+0

啊,不知道这是怎么爬的。你对这个错误是正确的,但是这个改变后问题依然存在。 –