简体   繁体   English

从一张纸复制一列中的每三个单元格,然后粘贴到另一张纸上

[英]Copy every three cells in a column from one sheet and paste to another sheet

I've seen posts regarding copying a range of data and pasting with added blanks, but I need something a bit more complicated. 我见过有关复制一系列数据并粘贴带有空白的文章,但是我需要更复杂一些。

I have a range of data which I need to copy from one sheet and paste into another. 我有一系列数据,需要从一张纸复制并粘贴到另一张纸。 The other sheet has data every 4th cell that I don't want to overwrite. 另一张纸上有我不想覆盖的第4个单元格的数据。 So I basically have a long range of data and I need copy three cells and paste to another sheet under this 4th cell I described, over and over again until I get to the end of the range of data. 因此,我基本上有很长的数据范围,我需要复制三个单元格并将其粘贴到我描述的第4个单元格下的另一张纸上,一遍又一遍,直到到达数据范围的尽头。

Example: This data from sheet 1 Sheet 1 data 示例:此数据来自工作表1工作表1数据

Needs to be pasted onto this sheet 2 sheet 2 test 需要粘贴到此表2 表2测试中

So the final result has sheet 2 where the "test" cells haven't been overwritten sheet 2 with data pasted 因此,最终结果为工作表2,其中“测试”单元尚未被粘贴数据覆盖工作表2

Thanks! 谢谢!

edit 编辑

Here is the code I'm using now: 这是我现在使用的代码:

'Now, copy specimen results from wb1: 现在,从wb1复制样本结果:

wb1.Sheets(1).Range("D53", wb1.Sheets(1).Range("D53" & NumOfwells * 4 + 44)).Copy wb1.Sheets(1).Range(“ D53”,wb1.Sheets(1).Range(“ D53”&NumOfwells * 4 + 44))。复制

'Now, paste to y worksheet:
wb2.Sheets("Worksheet").Range("J6").PasteSpecial

As you can see, it's a dynamic range being copied that could be more or less depending on an input number (NumOfwells), hence the calculation for the range. 如您所见,这是一个要复制的动态范围,其大小可能取决于输入数字(NumOfwells),因此将计算该范围。

And you can see where in the sheet the copying being done, ie D53 and down on from sheet one on wb1. 您可以看到要在工作表中的哪个位置进行复制,即D53,然后从wb1的工作表1开始向下复制。 Then pasted onto the second workbook starting at J6. 然后从J6开始粘贴到第二个工作簿上。

Welcome to StackOverflow. 欢迎使用StackOverflow。 If you post questions in the future please include the code that you've tried, and identify where it is failing. 如果将来发布问题,请提供您尝试过的代码,并确定失败的地方。

From your question & samples you really don't need to find every 4th row you are really just trying to paste data in places there isn't anything in the target area. 从您的问题和示例中,您实际上并不需要查找第4行,您只是在尝试将数据粘贴到目标区域中没有任何内容的地方。

The code uses the same basic loop to do either to show both cases. 该代码使用相同的基本循环来显示两种情况。 The following procedure lets you choose your range, and target sheet. 以下过程使您可以选择范围和目标表。

Sub test2()
    Call CopyData(Sheet1.Range("A3:A13"), sheet2)
End Sub

Private Sub CopyData(ByVal SourceRange As Range, ByRef TargetWorksheet As Worksheet)
    Dim oIndex As Long

    For oIndex = 1 To SourceRange.Rows.Count + 1
        ' Check for blanks
        'If TargetWorksheet.Cells(SourceRange.Row + oIndex - 1, 1) = "" Then
        '    TargetWorksheet.Cells(SourceRange.Row + oIndex - 1, 1).Value = SourceRange.Cells(oIndex, 1).Value
        'End If

        ' Skip every 4th row
        If (oIndex - 1) Mod 4 <> 0 Then
            TargetWorksheet.Cells(SourceRange.Row + oIndex - 1, 1).Value = SourceRange.Cells(oIndex, 1).Value
        End If

    Next
End Sub

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

相关问题 尝试将单元格从一张纸复制粘贴到另一张纸上? - Attempting copy paste cells from one sheet to another? 从一个工作表复制单元格并粘贴到另一个工作表中到可变单元格 - Copy cells from one sheet and paste in another to a variable cell Excel可以将某些单元格从一张纸复制/粘贴到另一张纸上,但要稍加改动 - Excel to copy / paste some cells from one sheet to another but with a twist 将一张图片从一张纸复制并粘贴到另一张纸上 - copy & paste a picture from one sheet to another 将范围从一张纸复制/粘贴到另一张纸 - Copy/Paste Range from one sheet to another 复制将行从一张纸粘贴到另一张纸 - Copy paste a row from one sheet to another 如何使用列名从一张工作表复制数据并粘贴到具有相同列名的另一张工作表? - How to copy data from one sheet using column name and paste to another sheet with same column name? 从一张纸上复制一列并多次粘贴到另一张纸上 - Copy one column from one sheet and paste in another sheet multiple times 缩短复制和粘贴 VBA 以将过滤的单元格从一张纸粘贴到另一张纸上 - Shorten Copy and Paste VBA to paste filtered cells from one sheet to another 从一张纸到另一张纸复制并粘贴一系列单元格,然后清除原始单元格中的数据 - Copy and paste a range of cells from one sheet to another then clear data from orignal cells
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM