将数据从一个电子表格复制/粘贴到另一个电子表格

时间:2022-08-18 09:46:53

Ok, I've been researching this for about 4 hours now. I had another similar post that solved one problem only to create another. This code grabs the same column of data from 2 spreadsheets. The first copy/paste works great (and fills rows A2:A191), but the first loop after that pastes the data from that spreadsheet starting at row A1332?? All of the cells from A192:A1331 are blank. The code should be looking for the first available empty cell looking from the bottom, up. What am I missing?

好的,我现在已经研究了大约4个小时了。我有另一个类似的帖子解决了一个问题只是为了创建另一个。此代码从2个电子表格中获取相同的数据列。第一个复制/粘贴工作得很好(并填充行A2:A191),但是之后的第一个循环粘贴来自该电子表格的数据从A1332行开始?来自A192:A1331的所有细胞都是空白的。代码应该是从底部向上查找第一个可用的空单元格。我错过了什么?

Here's the code in question. I have verified that it unlocked the second loops spreadsheet range cells, but after that it pastes it wrong? Formatting doesn't seem to be an issue? Is there "something" that could be in the cell that I'm not seeing?

这是有问题的代码。我已经验证它解锁了第二个循环电子表格范围单元格,但之后它贴错了?格式化似乎不是问题?在我看不到的细胞中是否存在“某种东西”?

 Set wbkCS = Workbooks.Open(strCutSheetFile(i))
        On Error GoTo 0
        Set wbkVer = Workbooks.Open(strVerifyFile)
        Set copyRng = Worksheets("Cutsheets").Range("A2")
    If copyRng = "" Then
            wbkCS.Worksheets("Cut Sheet").Range("S4:S2000").Locked = False
            wbkCS.Worksheets("Cut Sheet").Range("S4:S2000").Copy Destination:=wbkVer.Worksheets("Cutsheets").Range("A2")
    Else
            wbkCS.Worksheets("Cut Sheet").Range("S4:S2000").Locked = False
            wbkCS.Worksheets("Cut Sheet").Range("S4:S2000").Copy Destination:=wbkVer.Worksheets("Cutsheets").Range("A" & Range("A65536").End(xlUp).Row + 1)
     End If

1 个解决方案

#1


2  

Try qualifying the last range reference in your second copy statement,i.e.:

尝试在第二个副本声明中限定最后一个范围引用,即:

Instead of

代替

    .Range("A" & Range("A65536").End(xlUp).Row + 1)

Try

尝试

    .Range("A" & wbkVer.Worksheets("Cutsheets").Range("A65536").End(xlUp).Row + 1)

#1


2  

Try qualifying the last range reference in your second copy statement,i.e.:

尝试在第二个副本声明中限定最后一个范围引用,即:

Instead of

代替

    .Range("A" & Range("A65536").End(xlUp).Row + 1)

Try

尝试

    .Range("A" & wbkVer.Worksheets("Cutsheets").Range("A65536").End(xlUp).Row + 1)