【问题标题】:Excel Macro Copy paste into another xls file in the first empty rowExcel 宏复制粘贴到第一个空行中的另一个 xls 文件中
【发布时间】:2012-11-27 21:21:35
【问题描述】:

我目前正在从事一个数字项目,我必须分析来自 100 多个 FB excel 文件的数据。

我的部分分析过程包括从始终相同的特定单元格中提取数据。

如您所知,我想制作一个宏以避免无用的时间浪费。

我知道如何在文件中提取它,但我想调整我的宏以便将它复制到另一个文件中。

我的代码如下:

***Range("A9:D9").选择

选择.复制

Windows("test2.xlsx").Activate

ActiveSheet.Paste***

现在我想将数据粘贴到一个空行中,以便有数百行一个接一个(每个 FB 提取一个)。

有人会给我正确的代码以避免浪费大量时间吗?

【问题讨论】:

    标签: excel vba copy paste


    【解决方案1】:

    这是我用于类似操作以选择下一个可用单元格的代码片段。

    'Insert after Your Windows("test2.xlsx").Activate in place of your paste Code.....
    'This gives you the variable for the last cell with a value
    lastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
    'This section selects the next cell below your last used cell and pastes the information.
    ActiveSheet.Range("A" & lastRow + 1).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Application.CutCopyMode = False
    Rest of Code....
    

    我希望这就是你要找的。​​p>

    【讨论】:

      【解决方案2】:

      如果宏在“摘要”工作簿中且 FB 文件已打开且处于活动状态:

      ActiveSheet.Range("A9:D9")Copy _
         ThisWorkbook.Sheets("Data").Cells(Rows.Count,1).End(xlup).offset(1,0)
      

      【讨论】:

      • 感谢您的回答!我是初学者,我想我在某个地方犯了一个错误,我使用了你的代码并做了这个: Range("A9:D9").Select ActiveSheet.Range("A9:D9").Copy Windows("test2.xlsx" ).Activate Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Paste 但它无效。怎么了?
      • ...试试ActiveSheet.Range("A9:D9").Copy Workbooks("test2.xlsx").Sheets(1).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多