简体   繁体   English

Excel VBA 从一个工作表中复制范围并将其一次一个单元格地粘贴到另一张工作表中

[英]Excel VBA copy range from one sheet and paste it one cell at a time in another sheet

I'm trying to copy a range of data from one sheet and paste it, one cell at a time, in another sheet.我正在尝试从一张纸上复制一系列数据并将其粘贴到另一张纸上,一次一个单元格。

Let's say Sheet1 has the data in range A1 to C5.假设 Sheet1 的数据范围为 A1 到 C5。 A1 till last row needs to be copied and pasted in Sheet2 but one cell at a time starting from first not empty cell in column A till last copied data. A1 到最后一行需要复制并粘贴到 Sheet2 中,但一次一个单元格从 A 列中的第一个非空单元格开始直到最后复制的数据。 Is this possible?这可能吗?

The reason why this has to be done one cell at a time is because for every updated cell a small.txt file with the new value for this cell will be created.必须一次一个单元格执行此操作的原因是,对于每个更新的单元格,都会创建一个包含该单元格新值的 small.txt 文件。 This file is then used to sync data across multiple excel files.然后使用此文件跨多个 excel 文件同步数据。

Thanks in advance提前致谢

I wouldn't use the copy/paste functionality because it is much slower than directly assigning a cell's value to another cell.我不会使用复制/粘贴功能,因为它比直接将一个单元格的值分配给另一个单元格要慢得多。

Try something like this:尝试这样的事情:

Dim sourceWorksheet As Worksheet
Dim destinationWorksheet As Worksheet
Dim rangeToTransfer As Range

Set sourceWorksheet = myWorkbook.Worksheets("<name of source worksheet>")
Set destinationWorksheet = myWorkbook.Worksheets("<name of destination worksheet>")
Set rangeToTransfer = sourceWorksheet.Range("A1:C5")

Dim lastUsedRow As Integer
Dim rowIndex As Integer
Dim columnIndex As Integer

lastUsedRow = destinationWorksheet.Cells(destinationWorksheet.Rows.Count, 1).END(xlUp).row

For rowIndex = 1 To rangeToTransfer.Rows.Count
   For columnIndex = 1 To rangeToTransfer.Columns.Count
      destinationWorksheet.Cells(lastUsedRow + rowIndex, columnIndex).Value2 = rangeToTransfer.Cells(rowIndex, columnIndex).Value2      
   Next   
Next

I am making an assumption here:我在这里做一个假设:

  • You know the exact range you are trying to copy - A1:C5您知道您要复制的确切范围 - A1:C5

But I hope this points you in the right direction!但我希望这能为您指明正确的方向!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Excel宏复制单元格范围并将数据粘贴到另一个工作表 - Excel Macro Copy cell range & paste data one sheet to another 从另一张纸上的单元格值复制同一张纸中范围的一部分的粘贴范围 - Copy Range From One Sheet Paste Part of Range In Same Sheet Based On Cell Value On Another Sheet 将范围从一张纸复制/粘贴到另一张纸 - Copy/Paste Range from one sheet to another 一次将一个单元格从列表复制并粘贴到另一张工作表 - Copy and Paste one Cell at a time from a list to another sheet 使用excel VBA将数据从一张纸复制并粘贴到另一张纸,然后从第二张纸复制到第三张纸 - Copy and paste data from one a sheet to another sheet, and from second sheet to third using excel VBA 根据单元格colorindex从一个工作表的粘贴范围复制范围到另一工作表的另一工作表 - Copy Range From One Sheet Paste Part of Range In another Sheet Based On Cell colorindex Excel 2007 VBA:如何从一张纸上的动态范围复制和粘贴到另一张纸的第一行? - Excel 2007 VBA: How do I copy and paste from a dynamic range on one sheet to the first empty row of another sheet? 在每个工作表匹配的单元格上复制一个单元格并将其粘贴到另一个VBA - Copy a cell on one sheet and paste it on another VBA based on cell from each sheet matching excel vba 范围从一张纸复制到另一张纸(错误 1004) - excel vba range copy from one sheet to another (error 1004) Excel 使用 VBA 将单元格数据从一张纸复制到另一张纸 - Excel Copy Cell Data from one sheet to another using VBA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM