简体   繁体   English

将一个单一值多次复制粘贴到另一张纸上

[英]copy paste one single value multiple times to another sheet

I have a Column "ID" starting from Column C3 in sheet1 where all the id's are listed with an interval of 4 blank cells between each unique id's, as shown below 我从sheet1的C3列开始有一个“ ID”列,其中列出了所有ID,每个唯一ID之间的间隔为4个空白单元格,如下所示

在此处输入图片说明

I want to copy the id's and paste it to Sheet2 five times as shown below 我想复制ID并将其粘贴到Sheet2五次,如下所示

在此处输入图片说明

Can anyone sugggest how can i get this automated with the help of VBA 任何人都可以建议我如何在VBA的帮助下实现自动化

Put this formula in Sheet2!B2, 将此公式放在Sheet2!B2中,

=vlookup("zzzz", sheet1!C$3:C3, 1)

Fill down as necessary. 根据需要填写。

Try this one: 试试这个:

Sub copyCell()

    Dim idColumn As String
    Dim startRow, lastRow, row As Integer

    Dim sht1, sht2 As Worksheet

    Set sht1 = Worksheets("Sheet1") 'Setting sheet1
    Set sht2 = Worksheets("Sheet2") 'Setting sheet1

    idColumn = "C" 'Setting column id value column

    startRow = 1 'Setting the start row from sheet 1

    'Getting the last used row from sheet 1
    lastRow = sht1.Cells(sht1.Rows.Count, rowColumn).End(xlUp).row

    For row = startRow To lastRow Step 1

        'Check Id Value is empty or not
        If sht1.Range(idColumn & row) <> "" Then
            'If not empty, set value
            sht2.Range(idColumn & row) = sht1.Range(idColumn & row)
        Else
            'If empty, set value from previous row of sheet 2
            sht2.Range(idColumn & row) = sht2.Range(idColumn & (row - 1))
        End If

    Next row

End Sub

I already tested my code with your sample data. 我已经用您的示例数据测试了我的代码。 It works well for me. 这对我来说很有用。

I believe that will be helpful for you. 相信会对您有所帮助。

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

相关问题 从一张纸上复制一列并多次粘贴到另一张纸上 - Copy one column from one sheet and paste in another sheet multiple times VBA循环复制将一列与另一张表中的列一起多次粘贴 - VBA loop copy paste one column multiple times together with columns in another sheet 复制单元格内容并将其粘贴到另一张纸上多次 - Copy cell content and paste it to another sheet multiple times 复制具有 1 的列旁边的值,并将其粘贴到另一个工作表中的多个位置,逐个循环 - Copy the value next to the column that has 1, and paste it to multiple places in another sheet, looping through one by one 根据单个单元格值将项目复制/粘贴到另一个工作表上 - Copy/Paste Item onto another sheet based on a single cell value VBA:从一张纸到另一张纸的多次复制和粘贴 - VBA: multiple copy and paste from one sheet to another 将每个唯一值从一张纸复制并粘贴到另一张纸 - Copy & paste each unique value from one sheet to another 复制多个工作簿并粘贴到一张工作表中 - Copy multiple workbooks and paste in a single sheet 从另一张纸上的单元格值复制同一张纸中范围的一部分的粘贴范围 - Copy Range From One Sheet Paste Part of Range In Same Sheet Based On Cell Value On Another Sheet 将一张图片从一张纸复制并粘贴到另一张纸上 - copy & paste a picture from one sheet to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM